调整窗口大小时如何使用滚动 [英] how to use scroll, when i resize the window

查看:133
本文介绍了调整窗口大小时如何使用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to use scoll images or div's when i was resize the window, but it actually does not work. the only the part of scoll is working when i write it seperately. Anyone here to help?

$(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"
           });

         });
       }
    });

推荐答案

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

You shouldn't put $(window).scroll() in an event handler since itself is alos an event registration.

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

If you need the handler to be triggered on both resize and scroll, you can write it like this:

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);

这篇关于调整窗口大小时如何使用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆