- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个函数animation1()
和animation2()
。每个函数都包含一些链式动画 (animate()
)。每个动画集都有两个部分:
在场景 1 中移动对象 > 隐藏它们 > 在场景 2 上显示对象。
第二个动画集相反 - 隐藏场景 2 上的对象 > 显示场景 1 上的对象并将其向右移动
动画正在运行。
我需要的是使用以下规则将这些动画绑定(bind)到mousewheel
:
这是我的代码,它可以工作,但会运行多次,并由于多次触发 mousewheel
增量而造成很大困惑。我尝试了很多在 SO 上找到的解决方案,但没有任何运气。我还尝试解除绑定(bind)mousewheel
,它正在工作;但我不知道如何重新绑定(bind)它并向上滚动。
$(window).bind('DOMMouseScroll MozMousePixelScroll mousewheel onmousewheel', function(e){
//$(this).unbind('DOMMouseScroll MozMousePixelScroll mousewheel onmousewheel');
if (e.originalEvent.wheelDelta < 0 || e.originalEvent.detail > 0) {
if ($('.scene1 .image').is(':visible') && $('#content').find(":animated").length === 0) {
animation1();
}
}
else {
if ($('.scene2 .image').is(':visible') && $('#content').find(":animated").length === 0) {
animation2();
}
}
});
感谢您的建议!
更新此时,这是我最好的解决方案..动画仅触发一次(使用 jquery.mousewheel,但也可以在没有此库的情况下使用) http://jsfiddle.net/wkupb1Ln/6/
$('#content').mousewheel(function(event) {
if ($('.image').is(':animated') ) {
return false;
}
if ( (event.deltaY < 0) && $('.scene2 .image').hasClass('invisible') ) {
animation1();
}
if ( (event.deltaY > 0) && $('.scene1 .image').hasClass('invisible') ) {
animation2();
}
});
最佳答案
尝试这里找到的scrollstop/scrollstart插件:https://github.com/ssorallen/jquery-scrollstop
然后我会将代码重构为如下所示,通过计算特定时间间隔(此处为 250 毫秒)后的滚动来测量“增量”
$(window).on("scrollstart", function() {
var Position1 = $window.scrollTop();
setTimeout(function () {
var Position2 = $window.scrollTop(), delta = Position2 - Position1;
if (delta < 0 && $('.scene1 .image').is(':visible') && $('#content').find(":animated").length === 0) {
animation1();
} else {
if (delta > 0 && $('.scene2 .image').is(':visible') && $('#content').find(":animated").length === 0) {
animation2();
}
}
}, 250);
});
绑定(bind)到“scrollstart”应确保相应的函数仅触发一次。
关于jQuery 鼠标滚轮在动画未完成时仅触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26643997/
我相信绝大多数小伙伴在自学python时,运用pycharm进行编写程序时发现字体太小不方便进行编写,通常像codeblocks这样的编程软件可以通过“ctrl+滚轮”进行放大和缩小。而
在我的应用程序中,我使用了 Scroller零件。我似乎无法弄清楚我应该在哪个事件上设置一个监听器以便知道何时滚动内容。我试过Event.CHANGE在 Scroller.verticalScroll
我正在使用一个简单的 progressDialog,它运行正常但轮子没有进步: //Progress Dialog final ProgressDialog dialo
我想在点击文本字段时关闭键盘,以便为该文本字段下方的选择器留出空间。 struct ContentView: View { @State private var date = Date()
我是一名优秀的程序员,十分优秀!