コード:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jQuery/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$(document).keydown(function () {
alert("hello");
$('div').animate({ left: '+=10px' }, 500);
});
});
</script>
<style type="text/css">
div
{
height: 50px; width: 50px; background-color: Red;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
キーを押すたびにdivを右に移動したいのですが、何らかの理由でこれはうまくいきません。「こんにちは」というアラートが表示されるので、animate ステートメントに小さな間違いがあり、それを理解できない可能性があります。
なぜこれが機能しないのか、正しい方法を教えてください。
前もって感謝します。:)