javascript - 当用户滚动到网站部分时淡入 div

标签 javascript jquery html css

我有 Jquery 代码在页面加载时淡化某些 div。当用户在我的网页上滚动 2000 像素时,我将如何编辑此代码以触发此操作。

JQUERY

    $(function () { $(window).load(function() {
    $('.welcome-image').addClass('animated fadeInRightBig');
})
  var reset = function reset() {
          console.log($(this).scrollTop());
            // do stuff when window `.scrollTop()` > 75
            if ($(this).scrollTop() > 2000) {
              // turn off scroll event so `fx` not called
              // during ongoing animation
              $(this).off("scroll");
                // when all animations complete
                fx()
            }
        };
        // if `fx` should only be called once ,
        // change `.on()` to `.one()` ,
        // remove `.then()` callback following `fx()`
        // within `reset`
        $(window).on("scroll", reset);
    });

最佳答案

试试这个

<html>
<head></head>
<title></title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<style type="text/css">

body{
  height: 1000px;
}
</style>

<body>
 <h2>scroll the body to see the magic</h2>

</body>

<script type="text/javascript">
$(window).on("mousewheel", function() {
        var the_position = $(document).scrollTop();
        if (the_position > 200) 
          {
            $('body').css({"background-color":"red"});
          }
          else
          {
            $('body').css({"background-color":"white"});
          }
    });

</script>

</html>

根据需要更改功能和其他内容。这是一个让你和想法的例子。

关于javascript - 当用户滚动到网站部分时淡入 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39191042/

相关文章:

javascript - 选择的 ID 丢失

javascript - 如何从移动网页打开 Whatsapp 聊天?

javascript - HTML:如何使滚动速度更快

jquery - 如何在 AngularJs 中执行 jQuery 动画,例如淡入和淡出

javascript - SVG、jQuery 和 Internet Explorer

html - 为什么 firebug 会自动插入 </p>?

HTML 正文不滚动

javascript - Cordova 5白名单、Content-Security-Policy和本地网络ip

javascript - 了解 Backbone.js REST 调用

javascript - 如何记录 "catched"异常?