在JQuery不工作的情况下旋转和移动
Rotate and move with JQuery not working
我需要同时旋转和移动图像,实际上只工作一次,但然后只是移动而不是旋转。
这就是我所拥有的:
<!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>
相关文章:
- 使用KineticJS变换(移动/缩放/旋转)形状
- 如何水平移动旋转的画布
- 如何使我的功能360度旋转并上下移动
- 猫头鹰旋转木马-自动高度移动问题
- 如何在Javascript中移动元素的旋转点
- 如何旋转rect,并且它仍然根据其旋转沿正确的方向移动
- 用户键入时旋转的内容可编辑移动
- 在 HTML5 画布中沿路径旋转移动对象
- 三.js一个物体可以同时旋转和移动吗?
- 如何锁定在类固醇中旋转的场景.js - AppGyver移动应用程序
- 想要使用 html5 的画布优化捕获的图像调整大小和旋转的代码,现在在移动设备上发出内存不足警告
- 如何在phase.js中移动时旋转汽车
- OWL旋转木马移动+/-5张幻灯片
- 我可以使用旋转功能绕时钟移动一条线吗
- Three.js-鼠标移动时沿(0,0,0)旋转对象
- 使用JavaScript和setTimeout旋转HTML元素以模拟不断移动的对象
- IE10中鼠标移动时的图像旋转
- 在HTML画布中移动旋转对象
- 在JQuery不工作的情况下旋转和移动
- 变换:旋转移动视图