I tested this statement in my SeaMonkey browser and it fails.
(我在SeaMonkey浏览器中测试了此语句,但失败了。)
var delta = e.type == 'mousewheel' ? e.originalEvent.wheelDelta * -1 : 40 * e.originalEvent.detail;
Just in case, I looked at the deltaY and it works: +1 in one direction and -1 in the other, just as you determined in the other two implementations you have.
(以防万一,我查看了deltaY,它起作用了:一个方向+1,另一个方向-1,就像您在其他两个实现中所确定的那样。)
console.log(e.deltaY); // view console in FireBug
Looking at the event structure in Firebug, I can see that the event type is "mousewheel", and yet I do not see a wheelData field in the originalEvent.
(查看Firebug中的事件结构,可以看到事件类型为“ mousewheel”,但是在originalEvent中却看不到wheelData字段。)
And although there is a detail field, but that one remains at zero.
(而且,尽管有一个明细字段,但该字段仍为零。)
I would imagine that you are attempting to go to the next item only once you reach +/-3.
(我想您仅在达到+/- 3后才尝试转到下一个项目。)
I would suggest something of the sort to accomplish this feat:(我建议采取某种措施来实现这一壮举:)
// somewhere, initialize to zero
var current_position = 0;
// on mousewheel events
current_position += e.deltaY;
// you had a x 40 which would indicate that the limit is about 120 / 40
// if 3 is too small, you can always increase it to 5 or event 10...
if(current_position <= -3)
{
slider.nextSlide();
current_position = 0;
}
else if(current_position >= 3)
{
slider.prevSlide();
current_position = 0;
}
Otherwise you could verify that your allowScroll
flag works as expected.
(否则,您可以验证allowScroll
标志是否按预期工作。)
I do not program objects that way so I am not too sure whether it is correct or not.(我不会以这种方式编程对象,因此我不太确定它是否正确。)
(I use the prototype
syntax which is useful if you want to extend classes.)((我使用prototype
语法,如果要扩展类,该语法很有用。))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…