简体   繁体   English

scrollTop()上的fadeOut()== 0不起作用

[英]fadeOut() on scrollTop() == 0 doesn't work

I got a little Icon on my page which should fade in when I am on the top of my page. 我在页面上有一个小图标,当我在页面顶部时,该图标会淡出。 When I scroll down a bit, it should fade out. 当我向下滚动时,它应该淡出。 But when i go back up again, it reappears. 但是,当我再次返回时,它又出现了。 I thought that should work with this code: 我认为应该使用以下代码:

 if ($(document).scrollTop() === 0){
    $('#down').fadeIn(200);
    console.log("Hi");
  }
  else{
    $('#down').fadeOut(200);
    console.log("Bye");
  }

but obviously it doesn't. 但显然不是。 Here's a little codepen 这是一个小码笔

You need to add it inside onscroll functionality. 您需要将其添加到onscroll功能中。 For example: 例如:

 $(window).scroll(function(){

  });

or 要么

$( "#down" ).scroll(function() {
});

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

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