fullpage.js animation with onLeave and afterLoad

拟墨画扇 提交于 2019-12-13 02:57:16

问题


i'm using fullpage.js and i'd like to animate 2 images as soon as i get to the second section. looks like i can't make it work with css only, so i picked up some js code from the documentation. check this jsfiddle: http://jsfiddle.net/67oe1jvn/9/

the thing is: if i scroll down to the second section, the 2 images get animated and fade in from left and right sides. BUT if i change section, nothing happens... now i want the to "disappear" as soon as i leave the second section.

i used afterLoad and onLoad as said in the documentation, like this:

$.fn.fullpage({

afterLoad: function(anchorLink, index){
        var loadedSection = $(this);
        if(index == 1){
            $('#slidetext1 #rock').animate({right:"0px"});
            $('#slidetext1 #deer').animate({left:"0px"});
        }
    },
onLeave: function(index, nextIndex, direction){
        var leavingSection = $(this);
        if(index == 2 && direction =='up'){
            $('#slidetext1 #rock').animate({right:"-271px"});
            $('#slidetext1 #deer').animate({left:"-271px"});

      } else if(index == 2 && direction == 'down'){
            /* DO SOMETHING */
        }
}
});

i'm new with this plugins so would be cool if someone helps me :)

also i saw this guy posting a similar question that maybe can help clarifying what i need: fullPage.js onLeave event triggers .


回答1:


Three things:

  • If you post a jsfiddle, make sure it works... because it doesn't at all.

  • You are initializing fullPage.js twice in your site. Inside myjs.js and outside it..

  • You can create animations with just css if you want. Check this video.

If you want the images to dissappear again you'll have to tell fullPage.js to do it. It won't magically happen. Just use the onLeave again and say something like "whenever the next slide is not section 2, then hide my images".

if(nextIndex != 2){
   //hide images
}


来源:https://stackoverflow.com/questions/31467606/fullpage-js-animation-with-onleave-and-afterload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!