CSS3关键帧动画在chrome中工作,而不是firefox(CSS3 Keyframe animation working in chrome, not firefox)
我有一个关键帧动画,我将其悬停在导航菜单上。 当我将鼠标悬停在上面时,动画效果很好,但如果我将鼠标移开,我希望它能完成动画。 这个功能在Chrome中正常运行,但不是Firefox,我无法弄清楚原因。
jsFiddle: http : //jsfiddle.net/u95Lumm3/1/
有一点我注意到,在FF上,即使你将鼠标放在上面,动画也会重置。
简单地删除'mozAnimationEnd'不会像在Stackoverflow上的另一个相似的问题那样解决问题。
HTML:
<div style="width: 100px; height: 100px; background: green;"> <div class="nav-bnt"> <div></div> <div></div> <div></div> </div> </div>
脚本:
$('.nav-bnt').bind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { $('.nav-bnt').removeClass("animation"); }); $('.nav-bnt').hover(function(){ $('.nav-bnt').addClass("animation"); })
CSS:
.nav-bnt div, .nav-bnt div:nth-of-type(3) { top: -15px; bottom: 0; left: 0; right: 0; margin: auto; -moz-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -o-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -ms-transform: translate3d(-1px, 0px, 0px) rotate(0deg); transform: translate3d(-1px, 0px, 0px) rotate(0deg); } .nav-bnt div:nth-of-type(2) { top: 0; -moz-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -o-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -ms-transform: translate3d(-1px, 0px, 0px) rotate(0deg); transform: translate3d(-1px, 0px, 0px) rotate(0deg); } .nav-bnt div:nth-of-type(3) { top: 0; bottom: -16px; } .animation div:nth-of-type(2) { -webkit-animation: navanimateleft .5s; -moz-animation: navanimateleft .5s; -o-animation: navanimateleft .5s; -ms-animation: navanimateleft .5s; animation: navanimateleft .5s; } .animation div:nth-of-type(1), .animation div:nth-of-type(3) { -webkit-animation: navanimateright .5s; -moz-animation: navanimateright .5s; -ms-animation: navanimateright .5s; -o-animation: navanimateright .5s; animation: navanimateright .5s; } @-webkit-keyframes navanimateleft { 0% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {-webkit-transform: translate3d(-10px, 0px, 0px) rotate(0deg);} 60% {-webkit-transform: translate3d(-10px, 0px, 0px) rotate(180deg);} 100% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @keyframes navanimateleft { 0% {transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {transform: translate3d(-10px, 0px, 0px) rotate(0deg);} 60% {transform: translate3d(-10px, 0px, 0px) rotate(180deg);} 100% {transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @-webkit-keyframes navanimateright { 0% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {-webkit-transform: translate3d(10px, 0px, 0px) rotate(0deg);} 60% {-webkit-transform: translate3d(10px, 0px, 0px) rotate(180deg);} 100% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @keyframes navanimateright { 0% {transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {transform: translate3d(10px, 0px, 0px) rotate(0deg);} 60% {transform: translate3d(10px, 0px, 0px) rotate(180deg);} 100% {transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } .nav-bnt { position: relative; width: 50px; height: 50px; top: 25px; cursor: pointer; background: rgba(255,255,255, 1); -webkit-border-radius: 25px; -moz-border-radius: 25px; border-radius: 25px; z-index: 999; transition: all 0.25s linear; -moz-transition: all 0.25s linear; -webkit-transition: all 0.25s linear; -o-transition: all 0.25s linear; } .nav-bnt:hover { -moz-transform: scale(1.10); -webkit-transform: scale(1.10); -o-transform: scale(1.10); -ms-transform: scale(1.10); transform: scale(1.10); } .nav-bnt div { backface-visibility: hidden; background-color: #993399; height: 3px; width: 15px; position: absolute; transition: all 0.35s ease-in-out; -moz-transition: all 0.35s ease-in-out; -webkit-transition: all 0.35s ease-in-out; -o-transition: all 0.35s ease-in-out; }
I have a key frame animation that I animate on hover for a navigation menu. When I hover over, the animation works just fine but I want it to finish the animation if I move the mouse off. This function is working correctly in Chrome, but not Firefox and I can't figure out why.
jsFiddle: http://jsfiddle.net/u95Lumm3/1/
One thing I have noticed, on FF the animation resets even if you keep the mouse on top.
Simply removing 'mozAnimationEnd' does not fix the issue like it does in a different, but similar, question on Stackoverflow.
HTML:
<div style="width: 100px; height: 100px; background: green;"> <div class="nav-bnt"> <div></div> <div></div> <div></div> </div> </div>
Script:
$('.nav-bnt').bind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { $('.nav-bnt').removeClass("animation"); }); $('.nav-bnt').hover(function(){ $('.nav-bnt').addClass("animation"); })
CSS:
.nav-bnt div, .nav-bnt div:nth-of-type(3) { top: -15px; bottom: 0; left: 0; right: 0; margin: auto; -moz-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -o-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -ms-transform: translate3d(-1px, 0px, 0px) rotate(0deg); transform: translate3d(-1px, 0px, 0px) rotate(0deg); } .nav-bnt div:nth-of-type(2) { top: 0; -moz-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -o-transform: translate3d(-1px, 0px, 0px) rotate(0deg); -ms-transform: translate3d(-1px, 0px, 0px) rotate(0deg); transform: translate3d(-1px, 0px, 0px) rotate(0deg); } .nav-bnt div:nth-of-type(3) { top: 0; bottom: -16px; } .animation div:nth-of-type(2) { -webkit-animation: navanimateleft .5s; -moz-animation: navanimateleft .5s; -o-animation: navanimateleft .5s; -ms-animation: navanimateleft .5s; animation: navanimateleft .5s; } .animation div:nth-of-type(1), .animation div:nth-of-type(3) { -webkit-animation: navanimateright .5s; -moz-animation: navanimateright .5s; -ms-animation: navanimateright .5s; -o-animation: navanimateright .5s; animation: navanimateright .5s; } @-webkit-keyframes navanimateleft { 0% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {-webkit-transform: translate3d(-10px, 0px, 0px) rotate(0deg);} 60% {-webkit-transform: translate3d(-10px, 0px, 0px) rotate(180deg);} 100% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @keyframes navanimateleft { 0% {transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {transform: translate3d(-10px, 0px, 0px) rotate(0deg);} 60% {transform: translate3d(-10px, 0px, 0px) rotate(180deg);} 100% {transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @-webkit-keyframes navanimateright { 0% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {-webkit-transform: translate3d(10px, 0px, 0px) rotate(0deg);} 60% {-webkit-transform: translate3d(10px, 0px, 0px) rotate(180deg);} 100% {-webkit-transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } @keyframes navanimateright { 0% {transform: translate3d(-1px, 0px, 0px) rotate(0deg);} 30% {transform: translate3d(10px, 0px, 0px) rotate(0deg);} 60% {transform: translate3d(10px, 0px, 0px) rotate(180deg);} 100% {transform: translate3d(-1px, 0px, 0px) rotate(180deg);} } .nav-bnt { position: relative; width: 50px; height: 50px; top: 25px; cursor: pointer; background: rgba(255,255,255, 1); -webkit-border-radius: 25px; -moz-border-radius: 25px; border-radius: 25px; z-index: 999; transition: all 0.25s linear; -moz-transition: all 0.25s linear; -webkit-transition: all 0.25s linear; -o-transition: all 0.25s linear; } .nav-bnt:hover { -moz-transform: scale(1.10); -webkit-transform: scale(1.10); -o-transform: scale(1.10); -ms-transform: scale(1.10); transform: scale(1.10); } .nav-bnt div { backface-visibility: hidden; background-color: #993399; height: 3px; width: 15px; position: absolute; transition: all 0.35s ease-in-out; -moz-transition: all 0.35s ease-in-out; -webkit-transition: all 0.35s ease-in-out; -o-transition: all 0.35s ease-in-out; }
原文:https://stackoverflow.com/questions/29979180
最满意答案
你有一个竞争事件处理程序的情况,最后一个(将高度设置为5.7em的那个)胜出。 事件处理程序实际上是堆叠的,因此您不断添加关闭菜单的其他副本。
尝试独立保持打开/关闭状态。 像这样( jsfiddle ):
$(document).ready(function () { $('#nav').data('open', 0).mouseup(function () { if ($(this).data('open') == 0) { $(this).css('height', '33em').data('open', 1); } else { $(this).css('height', '5.7em').data('open', 0); } }); });
或者更好的是,将CSS细节移至CSS类:
#nav { height: 5.7em; } .open { height: 33em !important; }
...只需开启和关闭该类( jsfiddle ):
$(document).ready(function () { $('#nav').mouseup(function () { $(this).toggleClass('open'); }); });
You have a case of competing event handlers, and the last one (the one that sets the height to 5.7em) wins. The event handlers actually stack, so you keep adding additional copies of the one that closes the menu.
Try maintaining the open/closed state independently. Something like this (jsfiddle):
$(document).ready(function () { $('#nav').data('open', 0).mouseup(function () { if ($(this).data('open') == 0) { $(this).css('height', '33em').data('open', 1); } else { $(this).css('height', '5.7em').data('open', 0); } }); });
Or better yet, move the CSS details to a CSS class:
#nav { height: 5.7em; } .open { height: 33em !important; }
...and just toggle that class on and off (jsfiddle):
$(document).ready(function () { $('#nav').mouseup(function () { $(this).toggleClass('open'); }); });
相关问答
更多-
您的代码无法正常工作的原因是您正在使用上下文选择器。 所以它的意思是:找到#trigger2并在其中查找#trigger1。 但你想要的是使用多选择器 。 $("#trigger1, #trigger2").click( ... ) 或者我只使用一个公共类,因此您不必跟踪ID $(".commonClass").click( ... ) The reason why your code is not working is you are using a context selector. So what ...
-
使用MySQL触发器(Using MySQL triggers)[2023-07-09]
扩展我的评论,我在我的MySQL服务器上创建了两个表,如下所示: CREATE TABLE items ( item_id int not null auto_increment primary key, item_amount double, description varchar(50) ); CREATE TABLE item_records ( record_id int not null auto_increment primary key, item_id int ... -
你需要坚持this值,你可以通过多种方式来实现它,jQuery 1.4+为你提供$.proxy方法,例如: //... $(document).bind("customEvent", $.proxy(this.onCustomAction, this)); // or $(document).bind("customEvent", $.proxy(this, 'onCustomAction')); //... You need to persist the this value, you can do i ...
-
jQuery事件触发器只会触发一次...我需要它们始终工作(jQuery event triggers only fire once…I need them to always work)[2023-04-05]
你有一个竞争事件处理程序的情况,最后一个(将高度设置为5.7em的那个)胜出。 事件处理程序实际上是堆叠的,因此您不断添加关闭菜单的其他副本。 尝试独立保持打开/关闭状态。 像这样( jsfiddle ): $(document).ready(function () { $('#nav').data('open', 0).mouseup(function () { if ($(this).data('open') == 0) { $(this).css('he ... -
Firebird触发器不会从应用程序触发,但可以在数据库工具中使用(Firebird triggers do not fire from application but do work in DB tools)[2023-08-09]
像大多数奇怪的问题一样,由于应用程序工作原理的思考过程,这个答案很容易被忽略。 更不用说学习/接受新项目和疯狂通勤的厌倦。 无论如何;-)。 事实证明触发器实际上是从应用程序工作,但是一个未刷新的数据感知控件在单击“保存”按钮时更改了值。 这是一个包含多个标签的表单。 表A(由触发器更新的表)显示在第一个选项卡中,其中包含数据感知控件的字段。 表B(在表A中有两个触发器,用于更新表中字段的表)显示在数据感知网格的第二个选项卡中。 当在网格中添加/删除行时,它在DB-中被删除,但因为表A从未在应用程序中刷新 ... -
对于你的第一个问题,没有看到一个例子就有点难以说。 我可能会弄错,但我很确定$ .trigger()不会像你使用它一样工作。 它必须附加到jQuery对象,例如。 $().trigger() 。 对于你的第二个问题......你不必完全使用DOM元素,但你可以使用像$({}).on()这样的空jquery对象。 看到这个小提琴 。 希望这会有所帮助。 另外,您可能会将jQuery对象方法与核心方法混淆。 这里有一些信息以防万一。 For your first issue, it's a little har ...
-
事件触发器不起作用(Event triggers don't work)[2022-04-13]
我改变了你的代码: 将RoutedEvent更改为Grid.Loaded 添加了TargetName以及对Grid的引用 将TargetProperty更改为Grid.Opacity 查看以下代码:... -
JQuery - 事件委托系列中只有最后一个事件处理程序触发器?(JQuery - only last event handler triggers in event delegation series?)[2023-06-26]
在每个$($slider).on('click',$dotNumber,function() {...}行中,将$ dotNumber替换为'#dot-number' 。 示例: $($slider).on('click','#dot-1',function() {...} 我不知道是否有一种特殊的方法来传递一个jQuery对象来指定一个子元素来定位,但我知道将CSS选择器添加为第二个参数就可以了。 根据手册页 ,第二个参数(如果它不是回调)是一个字符串。 In each of the $($slider) ... -
我的第一个建议是不使用全局点击处理程序。 而是将其绑定到搜索字段$('#searchField').click() 。 其次,您可能希望在搜索框中使用模糊和焦点事件来触发隐藏内容。 现场演示将有助于缩小您想要实现的目标。 My first suggestion would be to not use a global click handler. Instead bind it to the search field $('#searchField').click(). Second, you might ...
-
SELECT上的触发器(Fire triggers on SELECT)[2023-01-17]
我知道只有两种方法可以做到这一点而且都没有触发。 您可以使用存储过程来运行查询,并将查询记录到表中以及您想要了解的其他信息。 您可以使用SQL Server的审核功能 。 我从来没有使用过后者,所以我不能说易用性。 There are only two ways I know that you can do this and neither are trigger. You can use a stored procedure to run the query and log the query to a ...