【问题标题】:Trigger mousewheel to scroll left to right on desktop and top to bottom on window width below 768px触发鼠标滚轮在桌面上从左到右滚动,在窗口宽度低于 768 像素时从上到下滚动
【发布时间】:2015-09-05 18:49:00
【问题描述】:

我正在尝试触发鼠标滚轮在桌面上从左到右滚动,在窗口宽度低于 768 像素时从上到下滚动。

这是我目前得到的:

jQuery(document).ready(function($) {
    if( $(this).width() > 768 ) {
    $('html, body, *').mousewheel(function(e, delta) {
        this.scrollLeft -= (delta * 40);
        e.preventDefault();
    });
    }
$(window).resize(function() {
        if( $(this).width() > 768 ) {
    $('html, body, *').mousewheel(function(e, delta) {
        this.scrollLeft -= (delta * 40);
        e.preventDefault();
    });
    }
  });
});

在页面加载时工作正常,但在调整大小时不会改变,所以我猜 sn-p 的调整大小部分有问题。

【问题讨论】:

    标签: javascript jquery wordpress resize


    【解决方案1】:

    尝试创建一个函数,然后在每次调整大小时运行该函数:

    jQuery(document).ready(function($) {
    
        function mouseScroll(){
            $('html, body, *').mousewheel(function(e, delta) {
                this.scrollLeft -= (delta * 40);
                e.preventDefault();
            });
        }
    
        if( $(window).width() > 768 ) {
            mouseScroll();
        }
    
        $(window).resize(function() {
            if( $(window).width() > 768 ) {
                mouseScroll();
            }
        });
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多