为了账号安全,请及时绑定邮箱和手机立即绑定

这样做为什么不可以?

帮忙看看,这样为什么不可以?

正在回答

5 回答

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jQuery动画特效</title>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
            
        <script type="text/javascript">
            function l(){
                $("div").animate({left:"-=50px"},3000)
            }
            function r(){
                $("div").animate({left:"+=50px"},3000)
            }
        </script>
    </head>
    <style>
        div{
            position:fixed;
            height:100px;
            width:100px;
            background:red;
            border:3px solid green;
            line-height:100px;
            text-align:center;
        }
        #left {
            position: absolute;
            top: 120px;
        }
        #right {
            position: absolute;
            top: 120px;
            left: 60px;
        }
    </style>
    <body>
    <div id="test">快让我漂</div>
    <input id="left" type="button" value="左移" onclick="l()">
    <input id="right" type="button" value="右移" onclick="r()">

    </body>
</html>


0 回复 有任何疑惑可以回复我~
#1

Y_du 回复 隐匿山猫 提问者

三个问题,你的div没有定位。 div{ height:100px; width:100px; background:red; border:3px solid green; line-height:100px; text-align:center; } 这个要加定位 position
2015-08-20 回复 有任何疑惑可以回复我~
#2

隐匿山猫 提问者 回复 Y_du

谢谢,终于搞懂了
2015-08-20 回复 有任何疑惑可以回复我~

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
        <title>jQuery动画特效</title>
    </head>
    <style>
        div{
            height:100px;
            width:100px;
            background:red;
            border:3px solid green;
            line-height:100px;
            text-align:center;
        }
        #left{
            position: absolute;
            top: 120px;
        }
        #right{
            position: absolute;
            top: 120px;
            left:60px;
        }
    </style>
    <body>
    <div id="test">快让我漂</div>
    <input id="left" type="button" value="左移" onclick="l()">
    <input id="right" type="button" value="右移" onclick="r()">
    
    <script type="text/javascript">
        function l(){
            $("div").animate({left:"-=50px"},3000)
        }
        function r(){
            $("div").animate({left:"+=50px"},3000)
        }
    </script>
    </body>
</html>

0 回复 有任何疑惑可以回复我~

还是不行啊

0 回复 有任何疑惑可以回复我~

你的代码有三个问题

1. 要引入jquery:<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>

2 js文件头错了是<script type="text/javascript">,而不是<script type="test/javascript">

3 .animate 对应的div要定位


0 回复 有任何疑惑可以回复我~
#1

隐匿山猫 提问者

还是不行啊
2015-08-20 回复 有任何疑惑可以回复我~
#2

Y_du 回复 隐匿山猫 提问者

可以的,我都试过了。我给你贴代码吧
2015-08-20 回复 有任何疑惑可以回复我~
#3

隐匿山猫 提问者 回复 Y_du

嗯嗯,贴
2015-08-20 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
jQuery基础课程
  • 参与学习       154801    人
  • 解答问题       7184    个

加入课程学习,有效提高前端开发速度

进入课程

这样做为什么不可以?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信