gpt4 book ai didi

javascript - 强制停止点击事件

转载 作者:行者123 更新时间:2023-11-28 18:41:09 27 4
gpt4 key购买 nike

快速点击.circle,子元素star根据点击多次启动fadeinfadeout 。我希望在 .circle 完成动画时停止所有star效果。所以,我尝试使用 .off(),但效果仍然播放。

我想做的是,点击.circle效果播放,直接悬停结束效果,再次点击并再次播放。抱歉我的英语不好。如果我做错了请给一些建议,谢谢

        $(".contentitem").hover(
function (e) {
var dataid = $(this).data("id");
var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
$(".circle").stop().animate({ 'top': videoposition_top + "px" }, 500, function () {
$(".circle").off();
});

}, // over
function (e) {
var dataid = $(this).data("id");
var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
$(".circle").stop().animate({ 'top': videoposition_top + "px" }, 500, function () {
$(".circle").off();
});

} // out
);
$(".circle").on('click',function(){
$(".circleflyingstar div.star06").fadeIn(100).delay(500).fadeOut(100);
$(".circleflyingstar div.star02").fadeIn(200).delay(500).fadeOut(200);
$(".circleflyingstar div.star05").fadeIn(300).delay(500).fadeOut(300);
$(".circleflyingstar div.star03").fadeIn(400).delay(500).fadeOut(400);
$(".circleflyingstar div.star04").fadeIn(500).delay(500).fadeOut(500);
$(".circleflyingstar div.star01").fadeIn(600).delay(500).fadeOut(600);
});
.circle
{
height: 50px;
width: 50px;
position: absolute;
border-radius: 50%;
background-color: #fff;
z-index: 5;
border: 1px solid #ccc;
left: 0px;
top: 50px;
cursor: pointer;
border-top: 5px solid #EC9397;
border-left: 5px solid #EC9397;
border-bottom: 5px solid #F2C90D;
border-right: 5px solid #F2C90D;
left:50px;
top:100px;
}
.circleflyingstar
{
position: absolute;
top: -110px;
}
.circleflyingstar div.star01{
width:20px;
height:20px;
background-color:rgba(0,0,0,0.2);
position:absolute;
left:-20px;
}
.circleflyingstar div.star02{
width:20px;
height:20px;
background-color:rgba(0,0,0,0.4);
position:absolute;
top: 35px;
left: 20px;
display:none;
}
.circleflyingstar div.star03{
width:20px;
height:20px;
background-color:rgba(0,0,0,0.6);
top: 20px;
display:none;
}
.circleflyingstar div.star04{
width:20px;
height:20px;
background-color:rgba(0,0,0,0.8);
position: absolute;
display:none;
}
.circleflyingstar div.star05{
width:20px;
height:20px;
background-color:rgba(0,0,0,1);
position: absolute;
top: 34px;
left: -6px;
display:none;
}
.circleflyingstar div.star06{
width:20px;
height:20px;
background-color:rgba(0,0,0,0.2);
position: absolute;
top: 65px;
left: -10px;
display:none;
}

.contentitem{
width:500px;
height:400px;
background-color:#123;
margin-left:100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="circle">
<div class="circleflyingstar">
<div class="star01"></div>
<div class="star02"></div>
<div class="star03"></div>
<div class="star04"></div>
<div class="star05"></div>
<div class="star06"></div>
</div>
</div>


<div id="contentitem_123456" class="contentitem" data-id="123456"></div>

最佳答案

尝试使用 .one() 事件替换 .hover() ;使用 mouseenter 停止 .finish() 元素 父 div 从第一个 className 事件后 circleflyingstarhover 上的 .contentitem 动画开始

$(".contentitem").one("mouseenter", 
function(e) {
var dataid = $(this).data("id");
var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
$(".circle").stop().animate({
'top': videoposition_top + "px"
}, 500);
$(this).mouseenter(function() {
$("[class^=circleflyingstar] div").finish()
})
}
);
$(".circle").on('click', function() {
$(".circleflyingstar div.star06").fadeIn(100).delay(500).fadeOut(100);
$(".circleflyingstar div.star02").fadeIn(200).delay(500).fadeOut(200);
$(".circleflyingstar div.star05").fadeIn(300).delay(500).fadeOut(300);
$(".circleflyingstar div.star03").fadeIn(400).delay(500).fadeOut(400);
$(".circleflyingstar div.star04").fadeIn(500).delay(500).fadeOut(500);
$(".circleflyingstar div.star01").fadeIn(600).delay(500).fadeOut(600);
});
.circle {
height: 50px;
width: 50px;
position: absolute;
border-radius: 50%;
background-color: #fff;
z-index: 5;
border: 1px solid #ccc;
left: 0px;
top: 50px;
cursor: pointer;
border-top: 5px solid #EC9397;
border-left: 5px solid #EC9397;
border-bottom: 5px solid #F2C90D;
border-right: 5px solid #F2C90D;
left: 50px;
top: 100px;
}
.circleflyingstar {
position: absolute;
top: -110px;
}
.circleflyingstar div.star01 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 0.2);
position: absolute;
left: -20px;
}
.circleflyingstar div.star02 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
top: 35px;
left: 20px;
display: none;
}
.circleflyingstar div.star03 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 0.6);
top: 20px;
display: none;
}
.circleflyingstar div.star04 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 0.8);
position: absolute;
display: none;
}
.circleflyingstar div.star05 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 1);
position: absolute;
top: 34px;
left: -6px;
display: none;
}
.circleflyingstar div.star06 {
width: 20px;
height: 20px;
background-color: rgba(0, 0, 0, 0.2);
position: absolute;
top: 65px;
left: -10px;
display: none;
}
.contentitem {
width: 500px;
height: 400px;
background-color: #123;
margin-left: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="circle">
<div class="circleflyingstar">
<div class="star01"></div>
<div class="star02"></div>
<div class="star03"></div>
<div class="star04"></div>
<div class="star05"></div>
<div class="star06"></div>
</div>
</div>


<div id="contentitem_123456" class="contentitem" data-id="123456"></div>

关于javascript - 强制停止点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36050867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com