gpt4 book ai didi

javascript - 旋转和移动 JQuery 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:00 26 4
gpt4 key购买 nike

我需要同时旋转和移动一张图片,实际上只工作一次,但之后只是移动而不是旋转。

这是我的:

<!Doctype html>
<html>
<head>
<meta charset ="utf-8">
<title>JQuery Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script>
$(document).ready(MyMain);
function MyMain(){

$(".cartman").hover(MoveCartman,Normal); //on hover Eric Cartman

var v1=100; //variable to move Cartman

function MoveCartman(){
$(this).attr("src","CartmanNude.png");
$(this).css({
"margin-top":v1+"px",
"transform":"rotateZ(-360deg)",
"transition":"1s"
});
if (v1<200){v1+=100;}
else {v1=0;}
}
function Normal(){
$(this).attr("src","CartmanNormal.png");
}

}
</script>
</head>

<body>
<div class="container">
<div class="row">
<div style="padding:0px">
<img class="img-responsive cartman" src="CartmanNormal.png">
</div>
</div>
</div>
</body>
</html>

我认为这应该可以正常工作,但我不知道为什么悬停功能不能工作超过 1 次。

抱歉我的英语不好,谢谢。

最佳答案

尝试在 doctype 声明处将 D 替换为小写的 d ,将 all 添加到 transition持续时间之前的值; css "margin-top": "0px" , "transform": "rotateZ(0deg)"Normal 功能

.cartman {
transition: all 1s;
}
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>JQuery Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>

<script>
$(document).ready(MyMain);

function MyMain() {

$(".cartman").hover(MoveCartman, Normal); //on hover Eric Cartman

var v1 = 100; //variable to move Cartman

function MoveCartman() {
$(this).attr("src", "http://lorempixel.com/100/100/cats");
$(this).css({
"margin-top": v1 + "px",
"transform": "rotateZ(-360deg)"
});
if (v1 < 200) {
v1 += 100;
} else {
v1 = 0;
}
}

function Normal() {
$(this).attr("src", "http://lorempixel.com/100/100/technics")
.css({
"margin-top": "0px",
"transform": "rotateZ(0deg)"
});
}

}
</script>
</head>

<body>
<div class="container">
<div class="row">
<div style="padding:0px">
<img class="img-responsive cartman" src="http://lorempixel.com/100/100/technics">
</div>
</div>
</div>
</body>

</html>

关于javascript - 旋转和移动 JQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33769903/

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