Last active
October 11, 2021 18:54
-
-
Save alanef/cca6f4865850cece76fd24cdea77cb16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // wfea_slide_count set externally | |
| // wfea_slide_speed milliseconds set externally | |
| (function ($) { | |
| function specific_slide(num) { | |
| while ( num != counter ) { | |
| counter++; | |
| if (counter > wfea_slide_count ) { | |
| counter = 1; | |
| } | |
| $('.wfea-slideshow > div:first') | |
| .fadeOut(100) | |
| .next() | |
| .fadeIn(100) | |
| .end() | |
| .appendTo('.wfea-slideshow'); | |
| } | |
| } | |
| } | |
| $('.wfea-slide-indicator').removeClass('.active'); | |
| $('.wfea-slide-indicator [data-slide-show="'+num+'"]').addClass('.active'); | |
| } | |
| function change_slide() { | |
| counter++; | |
| if (counter > wfea_slide_count ) { | |
| counter = 1; | |
| } | |
| $('.wfea-slide-indicator').removeClass('.active'); | |
| $('.wfea-slide-indicator [data-slide-show="'+num+'"]').addClass('.active'); | |
| $('.wfea-slideshow > div:first') | |
| .fadeOut(100) | |
| .next() | |
| .fadeIn(100) | |
| .end() | |
| .appendTo('.wfea-slideshow'); | |
| } | |
| } | |
| $(function () { | |
| if (wfea_slide_count > 1) { // only when more than one slide | |
| if (wfea_slide_speed > 0) { // auto rotate | |
| var counter = 1; | |
| var DELAY = wfea_slide_speed; | |
| var old_timestamp = Date.now(); | |
| function rotate(timestamp) { | |
| if (timestamp > old_timestamp + DELAY) { | |
| // HAVE WE WAITED LONG ENOUGH? | |
| old_timestamp = timestamp; | |
| change_slide(); | |
| } | |
| setInterval(function () { | |
| rotate(Date.now()); | |
| }, 100); | |
| } | |
| // speed is zero so no rotate | |
| $(".hero__slide-click").on("click", function (event) { | |
| event.preventDefault(); | |
| old_timestamp = Date.now(); | |
| change_slide(); | |
| }); | |
| $(".wfea-slide_indicator").on("click", function (event) { | |
| event.preventDefault(); | |
| old_timestamp = Date.now(); | |
| let num = $(this).data('slide-number') | |
| specific_slide(num); | |
| }); | |
| } | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment