Multiple Image Fadeout on scroll

て烟熏妆下的殇ゞ 提交于 2019-12-04 07:09:43

问题


I have a onepage and on each navigation point a image in the middle of the site changes color by fading.

I managed to fade in with: $("#active3").fadeIn(2000); However I have a issue fading it out again. Let me try to explain: I have 5 Navigation points with 5 different images. If I (for example) scroll from first to third navigation point im gonna have 3 pictures laying over each other since on every navigation point, one picture fades in.

If I then jump from third again to the first I have to get the first picture on top somehow ( which wouldn't work for me since z-index can not fade, or? ) or I fade 2 and 3 out.

So I tryed to fade out each image which is not on the active navigation point out. For example when I was on the second navigaton point the code would be:

$("#active1").fadeOut(2000);
$("#active2").fadeIn(2000);
$("#active3").fadeOut(2000);
$("#active4").fadeOut(2000);
$("#active5").fadeOut(2000);

But It seems that the fadeOuts queue and don't happen at the same time.

This is the site im working on: http://palmira-lopez.de

thank you for helping! Also as a sitenote, this is not a commercial project but a site for my mum :)


回答1:


But It seems that the fadeOuts queue

You can use .finish() to tell jquery to finish whatever is currently queued.

$("#active1").finish().fadeOut(2000);
$("#active2").finish().fadeIn(2000);
$("#active3").finish().fadeOut(2000);
$("#active4").finish().fadeOut(2000);
$("#active5").finish().fadeOut(2000);

this may not be what you want though and you may want .hide() for those that are not in the process.

You might be better adding a class and using css transitions.



来源:https://stackoverflow.com/questions/40082334/multiple-image-fadeout-on-scroll

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