<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()' –
嗯..它現在真的有效。我覺得很奇怪。感謝那。 –