jquery 动画在关闭时出现两次
Jquery Animation Occurs Twice on Close
我有这些称为标签的div,它们很小,然后当您单击它们时,它们会展开并显示其中的隐藏元素。 X (
<跨度> X 跨度>
) 也会出现。单击此 X 时,此标记 (div) 应关闭。在 Firefox 中,标签可以正常打开。然后在关闭时关闭并重新打开。我不知道为什么收盘后是开盘。
顺便说一句,我根本无法让前 3 行工作。
请记住,它在Chrome上工作正常。所以Firefox对Jquery的解释是不同的
。.HTML
<div class="row row1">
<div id="tag1" class="tag">
<p class="p1">Header</p>
<video id="VideoA1" class="VideoA" name="media">
<source src="">
<source src="" type="video/mp4">
<source src="" type="video/mv4">
</video>
<p id="X"><span id="X" class="glyphicon glyphicon-remove" aria-label="Close"></span></p>
<iframe id="player1" class="ytplayer" width="390" height="220" src="" frameborder="0" allowfullscreen></iframe>
<p class="text">Random Text</p>
</div>
</div>
简讯
//This will make the tags expand to take up the whole row when clicked
$(".row .tag").on('click', function(event1){
if(event1.target.id == "tag1") {
alert("hello");
return; //Do nothing if the X is closed
}
else {
$(this).siblings().hide();
$(this).animate({
width:"98%",
});
$(".VideoA", this).css('display', 'none');
$("img", this).addClass('offleft');
$(".tag").hover(function(){
$(this).css("cursor","default")
});
$(".glyphicon-remove", this).delay(1000).show();
$(".glyphicon-remove", this).parent().show();
$('iframe',this).show();
$('.text',this).show();
}
});
$(".row1 .glyphicon-remove").click(function(){
var clicked = this;
$(this).parent().hide();
$(".row1 iframe").hide();
$(".row1 .text").hide();
$(this).parent().parent().animate({
width: "400px",
},function(){
$(".row1 .VideoA").show();
$("img", this).removeClass('offleft');
$(".tag",this).css('cursor','pointer');
$(clicked).parent().parent().siblings().show();
});
event.stopPropagation();
});
$(".row2 .glyphicon-remove").click(function(){
var clicked = this;
$(this).parent().hide();
$(".row2 iframe").hide();
$(".row2 .text").hide();
$(this).parent().parent().animate({
width: "400px",
},function(){
$(".row2 .VideoA").show();
$("img", this).removeClass('offleft');
$(".tag",this).css('cursor','pointer');
$(clicked).parent().parent().siblings().show();
});
event.stopPropagation();
});
event
是未定义的。
$(".row2 .glyphicon-remove").click(function(event){
注入event
,否则stopPropagation
是没有用的。
我认为,Chrome 很严格,并且在undefined
它停止对当前函数的评估,即当它遇到undefined
值并停止对该特定闭包的评估 JS 时,它会抛出错误。
然而,似乎 firefox 继续评估并将click
冒泡到 DOM 树上。因此,在您的情况下,单击event
需要由您的函数使用,因此需要通过调用 event.stopPropagation()
并将event
注入您的闭包来手动stopPropagation
,或者您也可以简单地在函数末尾return false
,因为它是一个 jquery 事件对象,与调用 event.preventDefault()
和 event.stopPropagation()
相同。
例如
$(".row2 .glyphicon-remove").click(function(event){
//stop propagation for the event but continue to evaluate current function
event.stopPropagation();
var clicked = this;
$(this).parent().hide();
$(".row2 iframe").hide();
$(".row2 .text").hide();
$(this).parent().parent().animate({
width: "400px",
},function(){
$(".row2 .VideoA").show();
$("img", this).removeClass('offleft');
$(".tag",this).css('cursor','pointer');
$(clicked).parent().parent().siblings().show();
});
return false; //jquery event stop propagation + prevent default
});
相关文章:
- Meteor Router数据函数被调用两次
- 从MySQL数据库中获取输入数据需要两次页面刷新
- Module.start()已激发两次
- Jquery点击事件必须点击两次
- Append元素在运行两次函数后不显示
- 防止双击执行两次jQuery post请求
- 我必须点击两次才能激活任何按钮操作(离子/角度)
- 单击jQuery会激发两次
- 如何避免在树上走两次
- 使用wow.js显示两次动画对象
- jquery 使用承诺调用两次动画完成
- .is(“:animated”) 选择器在动画期间返回 true,并调用两次
- jquery 动画在关闭时出现两次
- Css动画发射两次;闪烁”;在firefox中
- Javascript/jQuery:动画发生两次
- 画布上的动画同时循环两次
- jQuery动画:回调调用两次
- 动画Javascript显示/隐藏按钮两次
- jQuery动画只工作一次或两次
- jQuery动画在运行时触发回调两次