Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

javascript - Reset jQuery function on page load?

I have the following code, basically runs an animation on click, waits 3000ms, then scrolls down to the next page. Problem is, unless I clear the cache and open a new incognito window, the animation/auto scroll only works once. I want it to work each time the page is refreshed. I'm using Wordpress and the fullpage.js plugin. Cheers!

jQuery:

var delay = 3000; //milliseconds
var timeoutId;
var animationIsFinished = false;
new fullpage('#fullpage', {

    onLeave: function(origin, destination, direction){

    var curTime = new Date().getTime();

    jQuery('.spring');

    clearTimeout(timeoutId);

    timeoutId = setTimeout(function(){
    animationIsFinished = true;

        fullpage_api.moveTo(destination.index + 1);
    }, delay);

    return animationIsFinished;},

HTML:

<script>
    let iconSkipForward = document.querySelector('.spring');
    let animationSkipForward = bodymovin.loadAnimation({
            container: iconSkipForward,
            renderer: 'svg',
            loop: false,
            autoplay: false,
            path: "https://assets1.lottiefiles.com/packages/lf20_8cxxpvp0.json"
    });
      iconSkipForward.addEventListener('click', function() {
      animationSkipForward.playSegments([0,86], true);
        }, {once : true});
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...