简体   繁体   English

jQuery FadeOut div无法淡入

[英]jquery fadeOut div unable to fadeIn

I have adapted this fiddle http://jsfiddle.net/onqn2gjj/4/ to fade my search bar out on scroll, but once the search bar is gone, I cannot get it back by clicking the search icon. 我已经修改了这个小提琴http://jsfiddle.net/onqn2gjj/4/,以使我的搜索栏在滚动时淡出,但是一旦搜索栏消失了,我就无法通过单击搜索图标来找回它。

How can I modify my script to stop this from happening please? 我该如何修改脚本以阻止这种情况发生?

Here is the website: http://uwinat.o2clite.com/ 这是网站: http : //uwinat.o2clite.com/

Thanks 谢谢

jQuery(document).ready(function($) {
$(window).scroll(function() {

if ($(this).scrollTop()>0)
 {
    $('.search').fadeOut();
 }
else
 {
  $('.search').fadeIn();
 }
   })
});

Is because on scroll you are hiding the parent of your element 是因为在滚动时您隐藏了元素的父级

you can see it here: http://screencast.com/t/zrnNrbeI 您可以在这里看到它: http : //screencast.com/t/zrnNrbeI

If you fix that it will work: http://screencast.com/t/H2m7K1636VER 如果您修复该问题将起作用: http : //screencast.com/t/H2m7K1636VER

Note 注意

I also recomend you to use a debouncer for you scrolling event... the scroll event by it self would kill your performance... the UnderscoreJS library has a good one. 我还建议您为滚动事件使用一个去抖器……滚动事件本身会杀死您的性能……UnderscoreJS库有一个不错的库。

Also try using css animations instead of Jquery. 也可以尝试使用CSS动画而不是Jquery。 You should always avoid using javascript animations... 您应该始终避免使用JavaScript动画...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM