gpt4 book ai didi

javascript - 如何在 mouseenter 和 mouseleave 上使用 jQuery 淡入淡出 2 个图像?

转载 作者:行者123 更新时间:2023-12-01 05:26:25 25 4
gpt4 key购买 nike

我有一个自定义按钮(代码如下)。我希望它:

  • mouseenter 上快速旋转 360 度(目前工作正常)
  • mouseenter 上快速淡入较暗的图像(目前也工作正常)
  • 不能在 mouseleave 上取消旋转(目前工作正常)

我还不知道如何:

  • mouseleave 上淡入原始图像(尚未工作)

我尝试过很多 jQuery 变体,包括 .hover.fadeTogglefadeInfadeOut 等以及animate,但似乎没有一个对我有用。

我是否错过了一些非常简单和明显的东西?

注意:我刚刚在这里使用了 Apple Logo 进行演示。如果我能让“鼠标离开时淡出”功能正常工作,我就可以将其转移到我的现实生活中。

  var thevalue = 1;
$("div.main").mouseenter(function() {

thevalue = thevalue + 1;
if (thevalue % 2 == 0) {
$(this).addClass("myopacity");
} else {
$(this).removeClass("myopacity");
}

$(this).addClass("change").delay(500).queue(function() {
$(this).removeClass("change").dequeue();
});

});
div.main {
width: 100px;
height: 100px;
}
div.main img {
width: 100%;
height: 100%;
}
.change {
-ms-transform: rotate(360deg);
/* IE 9 */
-webkit-transform: rotate(360deg);
/* Chrome, Safari, Opera */
transform: rotate(360deg);
transition-duration: .5s;
}
.myopacity {
opacity: 0.6;
}
<!DOCTYPE html>
<html>

<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

</head>

<body>

<div class="main">
<img src="https://image.freepik.com/free-icon/apple-logo_318-40184.jpg">
</div>

<p id="dis"></p>
</body>

</html>

提前致谢!

最佳答案

这就是你想要的吗?希望这对您有帮助。

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

</head>

<style type="text/css">

div.main{
width: 100px;
height: 100px;

}

div.main img{
width: 100%;
height: 100%;
}

.change{
-ms-transform: rotate(360deg); /* IE 9 */
-webkit-transform: rotate(360deg); /* Chrome, Safari, Opera */
transform: rotate(360deg);
transition-duration: 5s;
}


</style>


<body>

<div class="main">
<img src="https://image.freepik.com/free-icon/apple-logo_318-40184.jpg">
</div>

<p id="dis"></p>

<script type="text/javascript">

var thevalue = 1;
$("div.main").mouseenter(function(){
$(this).addClass("change").fadeTo('fast',0.7).delay(5000).queue(function(){
$(this).removeClass("change").fadeTo('slow',1.0).dequeue();
});

});



</script>




</body>


</html>

关于javascript - 如何在 mouseenter 和 mouseleave 上使用 jQuery 淡入淡出 2 个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606651/

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