鼠标滚轮,滚动模拟菜单上的单击

时间:2016-02-01 13:35:02

标签: jquery wordpress

我想在mousewhell轮换时,我菜单中的所有链接(锚文本), 在滚动(向上或向下)我想按页面100%的部分导航(所有部分/ div都是窗口屏幕高度的100%)。 这是基本主题: http://onistaweb.com/demo/wp/master/

我修改了这个脚本,但是没有完美地工作(滚动不规则, 有时它附魔和做一个循环),为什么??? 谢谢大家!

1 个答案:

答案 0 :(得分:0)

(function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery)

//相关代码

var lastAnimation = 0; var animationTime = 1000; //在ms var quietPeriod = 500; // ms,动画后忽略mousescroll的时间

function scrollThis(event,delta,deltaX,deltaY){var timeNow = new Date()。getTime();

deltaOfInterest = deltaY;

if (deltaOfInterest == 0) {
    return;
}

// Cancel scroll if currently animating or within quiet period
if(timeNow - lastAnimation < quietPeriod + animationTime) {
    event.preventDefault();
    return;
}

if (deltaOfInterest < 0) {
        jQuery("#navbar ul .active").next().find("a").trigger("click"); 

} 

else {
    //sali su
    //alert("scroll up");
    jQuery("#navbar ul .active").prev().find("a").trigger("click");     
}

}

jQuery的(文件).mousewheel(scrollThis);

});