<script>
var swidth = $(window).width();
var sheight = $(window).height();
$(document).ready(function(){
$("#box").animate({ //animates depending on screen size
top: (sheight*0.22)+"px",
left: (swidth*0.25)+"px",
width:(swidth*0.3)-40+"px",
height: (sheight*0.35)-40+"px",
}, 2000, function(){
$('<input type="button" value="My button">').appendTo(this)
.click(function(){
$(this).animate({ // reverses animation back to original size and location
top: "150px",
left: "100px",
width:"1px",
height: "1px",
}, 2000,)
});
});
});
</script>
如果我更换后工作...jQuery的动画不会点击
$(this).animate({ // reverses animation back to original size and location
top: "150px",
left: "100px",
width:"1px",
height: "1px",
}, 2000,)
...与...
alert("You clicked me!");
...它的工作原理。所以错误在反向动画的某处。但是哪里?提前感谢任何答案!
万分感谢。完美工作。我明白你的意思了。我尝试用''#box'替换'this',代码不起作用,你知道为什么吗? '(this).parent()'与'(“#box”)'不一样吗? –
@DennisCallanan它应该工作'$('#box')'而不是'$(this).parent()' –
嗯..它现在真的有效。我觉得很奇怪。感谢那。 –