gpt4 book ai didi

javascript - 当用户不再悬停时,如何使这个无限的 jquery 动画结束?

转载 作者:太空宇宙 更新时间:2023-11-04 07:02:37 25 4
gpt4 key购买 nike

当您将鼠标悬停在我的菜单中的三个元素中的任何一个上时,会有一个浅蓝色的点开始闪烁红色。当用户不再将鼠标悬停在 FormsItem1、FormsItem2 或 FormsItem3 div 上时,我希望该动画停止。我尝试使用 mouseover 和 mouseout 函数,但在我停止悬停后,颜色变化动画似乎只是任意继续。如何将颜色变化动画限制在用户悬停时?

这是我的 Jquery 代码:

<script>

$(document).ready(function(){

$(".dotIcon").animate({'opacity': '1'}, 1000);

$('#FormsItem1').mouseover(function(){
initList = setInterval(function dotColorChange(){
$("#dotIcon1").animate({'background-color': 'white'});
$("#dotIcon1").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
clearInterval(initList);
$("#dotIcon1").animate({'background-color': 'white'})
});

$('#FormsItem2').mouseover(function(){
initList = setInterval(function dotColorChange(){
$("#dotIcon2").animate({'background-color': 'white'});
$("#dotIcon2").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
clearInterval(initList);
$("#dotIcon2").animate({'background-color': 'white'})
});


$('#FormsItem3').mouseover(function(){
initList = setInterval(function dotColorChange(){
$("#dotIcon3").animate({'background-color': 'white'});
$("#dotIcon3").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
clearInterval(initList);
$("#dotIcon3").animate({'background-color': 'white'})
});


$("#FormsItem1").hover(function(){
$(".FormPreviewPane").css("background-color", "white");
$(".PreviewContainer").animate({'top': '195px'},100);
$("#PreviewLine").animate({'top': '77px'},200);
}, function(){
});


$("#FormsItem2").hover(function(){
$(".FormPreviewPane").css("background-color", "beige");
$("#PreviewLine").animate({'top': '157px'},200);
}, function(){
});

$("#FormsItem3").hover(function(){
$(".FormPreviewPane").css("background-color", "lightgray");
$("#PreviewLine").animate({'top': '237px'},200);
}, function(){
});

});


</script>

这是我的 CSS:

<style>


.opaqueBlock{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
opacity:0.6;
margin-left: 60px;
width: 360px;
height: 46px;
background-color: #486173;
border-radius: 10px;
}

.opaqueBlock:hover{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
opacity:0.8;
}

.formLinkContainer{
position: absolute;
}

.formTextSpan:hover + .opaqueBlock{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80) !important";
opacity: 0.8 !important;
}

.formTextSpan{
position: absolute;
z-index: 1; margin-left: 73px;
color: white;
margin-top: 7px;
font-family: 'Didact Gothic' !important;
font-size: 23px !important;
}

.dotIcon{
height: 30px;
width: 30px;
background-color: #D6EDFF; /*#E8F5FF*/
position: absolute;
margin-left:13px;
margin-top: 7px;
border-radius: 15px;
opacity: 0;
box-shadow: 0 0 10px 1px white;
}

.dotLine{
position: absolute;
left: 43px;
top: 22px;
stroke: white;
}


img{border: none;}

.FormPreviewPane {
position: absolute;
border: 1px dotted blue;
width: 340px;
height: 345px;
box-shadow: 0px 0px 33px 5px #848C9C;
z-index:1;
background-image: url('');
border-radius:50px;
opacity: 0.8;
}

.FormPreviewPane.stuck {
position:fixed;
top:0;
}

.FormPreviewPaneBackground{
position: absolute;
width: 337px;
height: 435px;
z-index: 0;
opacity:0.15;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=15)";
}

.PreviewContainer{
position: absolute;
top: 195px;
left: 550px;
width: 430px;
}

#PreviewLine{
stroke: #D6EDFF;
stroke-width:7;
transform: rotate(0deg);
opacity: 1.0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
position: absolute;
left: -129px; top: 77px;
}

#FormsItem1{top: 250px;}
#FormsItem2{top: 330px;}
#FormsItem3{top: 410px;}


</style>

这是我的 HTML:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <!--this version works with IE-->
<script type="text/javascript" src="https://code.jquery.com/color/jquery.color-2.1.2.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <!-- color change animator -->







<div id="WoodenBackgroundContainer" style="background-color: navy; height: 800px;">



<a id="PreviewContainerLink" href="" target="_blank">
<div class="PreviewContainer">
<svg id="PreviewLine" height="5" width="131"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<div class="FormPreviewPane"></div>
<div class="FormPreviewPaneBackground"></div>
</div>
</a>


<a href="#" target="_blank">
<div id="FormsItem1" class="formLinkContainer">
<div class="dotIcon" id="dotIcon1"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Internal Communication</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>

<a href="#" target="_blank">
<div id="FormsItem2" class="formLinkContainer">
<div class="dotIcon" id="dotIcon2"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Reports Package</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>

<a href="#" target="_blank">
<div id="FormsItem3" class="formLinkContainer">
<div class="dotIcon" id="dotIcon3"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Talking Points</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>



</div>
</div>

最佳答案

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <!--this version works with IE-->
<script type="text/javascript" src="https://code.jquery.com/color/jquery.color-2.1.2.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <!-- color change animator -->
<style>


.opaqueBlock{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
opacity:0.6;
margin-left: 60px;
width: 360px;
height: 46px;
background-color: #486173;
border-radius: 10px;
}

.opaqueBlock:hover{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
opacity:0.8;
}

.formLinkContainer{
position: absolute;
}

.formTextSpan:hover + .opaqueBlock{
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80) !important";
opacity: 0.8 !important;
}

.formTextSpan{
position: absolute;
z-index: 1; margin-left: 73px;
color: white;
margin-top: 7px;
font-family: 'Didact Gothic' !important;
font-size: 23px !important;
}

.dotIcon{
height: 30px;
width: 30px;
background-color: #D6EDFF; /*#E8F5FF*/
position: absolute;
margin-left:13px;
margin-top: 7px;
border-radius: 15px;
opacity: 0;
box-shadow: 0 0 10px 1px white;
}

.dotLine{
position: absolute;
left: 43px;
top: 22px;
stroke: white;
}


img{border: none;}

.FormPreviewPane {
position: absolute;
border: 1px dotted blue;
width: 340px;
height: 345px;
box-shadow: 0px 0px 33px 5px #848C9C;
z-index:1;
background-image: url('');
border-radius:50px;
opacity: 0.8;
}

.FormPreviewPane.stuck {
position:fixed;
top:0;
}

.FormPreviewPaneBackground{
position: absolute;
width: 337px;
height: 435px;
z-index: 0;
opacity:0.15;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=15)";
}

.PreviewContainer{
position: absolute;
top: 195px;
left: 550px;
width: 430px;
}

#PreviewLine{
stroke: #D6EDFF;
stroke-width:7;
transform: rotate(0deg);
opacity: 1.0;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
position: absolute;
left: -129px; top: 77px;
}

#FormsItem1{top: 250px;}
#FormsItem2{top: 330px;}
#FormsItem3{top: 410px;}


</style>






<div id="WoodenBackgroundContainer" style="background-color: navy; height: 800px;">



<a id="PreviewContainerLink" href="" target="_blank">
<div class="PreviewContainer">
<svg id="PreviewLine" height="5" width="131"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<div class="FormPreviewPane"></div>
<div class="FormPreviewPaneBackground"></div>
</div>
</a>


<a href="#" target="_blank">
<div id="FormsItem1" class="formLinkContainer">
<div class="dotIcon" id="dotIcon1"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Internal Communication</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>

<a href="#" target="_blank">
<div id="FormsItem2" class="formLinkContainer">
<div class="dotIcon" id="dotIcon2"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Reports Package</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>

<a href="#" target="_blank">
<div id="FormsItem3" class="formLinkContainer">
<div class="dotIcon" id="dotIcon3"></div>
<svg class="dotLine" height="5" width="17"><line x1="0" y1="0" x2="131" y2="0"/></svg>
<span class="formTextSpan">Talking Points</span>
<div class="opaqueBlock" style=""></div>
</div>
</a>



</div>
</div>

<script>

$(document).ready(function(){

$(".dotIcon").animate({'opacity': '1'}, 1000);
var initList;
$('#FormsItem1').mouseover(function(){
if (initList) clearInterval(initList);
initList = setInterval(function dotColorChange(){
$("#dotIcon1").animate({'background-color': 'white'});
$("#dotIcon1").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
clearInterval(initList);
$("#dotIcon1").animate({'background-color': 'white'}).finish();
});

$('#FormsItem2').mouseover(function(){
if (initList) clearInterval(initList);
initList = setInterval(function dotColorChange(){
$("#dotIcon2").animate({'background-color': 'white'});
$("#dotIcon2").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
clearInterval(initList);
$("#dotIcon2").animate({'background-color': 'white'}).finish();
});

$('#FormsItem3').mouseover(function(){
if (initList) clearInterval(initList);
initList = setInterval(function dotColorChange(){
$("#dotIcon3").animate({'background-color': 'white'});
$("#dotIcon3").animate({'background-color': 'red'})
},100);
}).mouseout(function(){
console.log('hei');
clearInterval(initList);
$("#dotIcon3").animate({'background-color': 'white'}).finish();
});


$("#FormsItem1").hover(function(){
$(".FormPreviewPane").css("background-color", "white");
$(".PreviewContainer").animate({'top': '195px'},100);
$("#PreviewLine").animate({'top': '77px'},200);
}, function(){
});


$("#FormsItem2").hover(function(){
$(".FormPreviewPane").css("background-color", "beige");
$("#PreviewLine").animate({'top': '157px'},200);
}, function(){
});

$("#FormsItem3").hover(function(){
$(".FormPreviewPane").css("background-color", "lightgray");
$("#PreviewLine").animate({'top': '237px'},200);
}, function(){
});

});


</script>

处理间隔时,请注意多次运行它们。您也可以调用 finish() 来停止动画

关于javascript - 当用户不再悬停时,如何使这个无限的 jquery 动画结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51903729/

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