好的,所以我正在放一张onclick调整大小的图像,(变大然后点击返回原始大小)
我使用JS完成了这个但是我似乎无法在大小之间的补间中暗示动画,我希望它明显变得更大而不是它扩展到大小而不仅仅是在两个实例之间轻弹。
下面是编码:
<script type="text/javascript">
<!--
var flag = true;
function resize() {
if(flag) {
document.getElementById("img1").style.width = "50px";
} else {
document.getElementById("img1").style.width = "280px";
}
(flag)?flag=false:flag=true;
}
//-->
</script>
<body onload="resize();">
<img id="img1" src="../images/attachicona.png" border="0" onClick="resize();" />
答案 0 :(得分:2)
您可以使用CSS3过渡来产生相同的效果。不需要javascript或jquery - css3 animation/transition/transform: How to make image grow?
或者您可以使用jquery动画 - http://forum.jquery.com/topic/image-resize-animation
答案 1 :(得分:1)
如果使用jquery
var flag = true;
$('#img1').click(function(e){
if(flag)
$(e.target).animate({width:'50px'}, 150, function(){
//do stuff after animation
});
else
$(e.target).animate({width:'280px'}, 150, function(){
//do stuff after animation
});
flag=!flag;
});