smooth scroll with mousewheel to next or previous div

心已入冬 提交于 2019-12-04 09:42:12

EDIT: I tweaked the fiddle a little bit. One of the two external scripts was using http: and since the link (before the edit) used https:, Chrome blocked it unless you pressed the little shield icon. I also updated to latest version.

This seems to work fine: http://jsfiddle.net/9Amdx/1707/

var current;

$(function() {          
    $('body').mousewheel(function(event, delta) {
        var $current = $('div.current');

        console.log(delta);
        console.log($current);

        if (delta > 0) {
            $prev = $current.prev();

            if ($prev.length) {
                $('body').scrollTo($prev, 100);
                $current.removeClass('current');
                $prev.addClass('current');
            }
        } else {
            $next = $current.next();

            if ($next.length) {
                $('body').scrollTo($next, 100);
                $current.removeClass('current');
                $next.addClass('current');
            }
        }

        event.preventDefault();
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!