我正在尝试在文档加载时将框从右向左移动50px。香港专业教育学院做了相当多的搜索,并陷入困境。

起初,我认为这很容易做到,而我本来打算将click事件编写为有趣,但是在这里我陷入了困境。

这是HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />

    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
    Remove this if you use the .htaccess -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
    <link rel="stylesheet" href="css/gameCSS.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
    <meta name="apple-mobile-web-app-capable" content="yes" />

    <link rel="apple-touch-icon" href="media/apple-touch-icon.png"/>
    <link href="media/apple-touch-startup-image-iphone.png" media="(device-width: 320px)" rel="apple-touch-startup-image"/>
    <link href="media/apple-touch-startup-image-iphone-retina.png" media="(device-width: 320px) and (-webkit-device-pixel-ratio: 2)" rel="apple-touch-startup-image"/>

    <script src="js/jgame.js"></script>

    <title>HTML</title>
    <meta name="description" content="" />
    <meta name="author" content="CREEE" />



</head>

<body>
    <div id="home" data-role="page">

    <div id="box">

    </div>


    <div id="obs">

    </div>


    </div>


</body>




这是我的CSS

#box {

width: 40px;
height: 40px;

background-color: blue;

margin: 1px;
top:10px;
position:absolute;}

#obs {width: 15px;
height: 15px;
border: solid, 2px;
background-color: red;}


这是我的jQuery

$(document).ready(function() {
$('#box').animate({left: "+=50px",'slow'}, 1000);
});

最佳答案

试试这个:

$('#box').animate({left: "+=50px"}, 1000);


删除'slow'checkout the fiddle here

I am trying to move the box from right to left, by 50px when the Document loads.
此注释不正确,您的代码将#box移到了left to right by 50px

09-30 16:08
查看更多