嗨,我有这个代码运作良好,但我仍然需要通过单选按钮控制动画的速度。所以我需要替换0.5s
-webkit-transition: all 0.5s ease-in-out;
使用变量,但我不确定如何实现它,无论是在javascript中还是在按钮中声明变量的值。 任何建议都非常感谢。 感谢。
JAVASCRIPT
document.getElementById('panner01').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 30;
div.style.webkitTransform = 'rotate('+deg+'deg)';
}
document.getElementById('panner02').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 60;
div.style.webkitTransform = 'rotate('+deg+'deg)';
}
document.getElementById('panner03').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 90;
div.style.webkitTransform = 'rotate('+deg+'deg)';
}
CSS
#panpos01 {
position:relative;
height: 200px;
width: 200px;
margin: 30px;
-webkit-transition: all 0.5s ease-in-out;
}
HTML
<div id="panimageloc01"><img id="panpos01" src="https://d30y9cdsu7xlg0.cloudfront.net/png/17392-200.png"></div>
<form action="">
<input type="radio" name="gender" id="panner01" value="1"> 1
<br>
<input type="radio" name="gender" id="panner02" value="2"> 2
<br>
<input type="radio" name="gender" id="panner03" value="3"> 3
</form>
答案 0 :(得分:0)
更改属性transitionDuration
document.getElementById('panner01').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 30;
div.style.transform = 'rotate(' + deg + 'deg)';
div.style.transitionDuration = '1.5s';
}
document.getElementById('panner02').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 60;
div.style.transform = 'rotate(' + deg + 'deg)';
div.style.transitionDuration = '0.5s';
}
document.getElementById('panner03').onclick = function() {
var div = document.getElementById('panpos01'),
deg = 90;
div.style.transform = 'rotate(' + deg + 'deg)';
div.style.transitionDuration = '5s';
}
#panpos01 {
position: relative;
height: 200px;
width: 200px;
margin: 30px;
transition: all 0.5s ease-in-out;
}
<div id="panimageloc01"><img id="panpos01" src="https://d30y9cdsu7xlg0.cloudfront.net/png/17392-200.png"></div>
<form action="">
<input type="radio" name="gender" id="panner01" value="1"> 1
<br>
<input type="radio" name="gender" id="panner02" value="2"> 2
<br>
<input type="radio" name="gender" id="panner03" value="3"> 3
</form>