【问题标题】:how to use scroll, when i resize the window当我调整窗口大小时如何使用滚动
【发布时间】:2019-10-19 19:47:21
【问题描述】:

我想在调整窗口大小时使用 scoll 图像或 div,但它实际上不起作用。当我单独编写时,scoll 的唯一部分正在工作。有人来帮忙吗?

$(window).resize(function() {
       if ($(window).width() >= 767) {
         $(window).scroll(function() {

           $(".careers-philosophy__image").css({
             "bottom": ($(window).scrollTop()/15) + "px"
           });

           $(".careers-philosophy__image2").css({
             "bottom": ($(window).scrollTop()/25) + "px"
           });

           $(".carrer-block").css({
             "bottom": ($(window).scrollTop()/10) + "px"
           });

           $(".fast").css({
             "bottom": ($(window).scrollTop()/5) + "px"
           });

         });
       }
    });

【问题讨论】:

    标签: jquery html css sass


    【解决方案1】:

    您不应该将$(window).scroll() 放在事件处理程序中,因为它本身就是一个事件注册。

    如果您需要同时在resizescroll 上触发处理程序,您可以这样编写:

    function handler(){
        if ($(window).width() >= 767) {
            $(".careers-philosophy__image").css({
                "bottom": ($(window).scrollTop() / 15) + "px"
            });
    
            $(".careers-philosophy__image2").css({
                "bottom": ($(window).scrollTop() / 25) + "px"
            });
    
            $(".carrer-block").css({
                "bottom": ($(window).scrollTop() / 10) + "px"
            });
    
            $(".fast").css({
                "bottom": ($(window).scrollTop() / 5) + "px"
            });
        }
    }
    
    $(window).resize(handler);
    $(window).scroll(handler);
    

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多