JQ中css不能实现和animate不能实现,不知道问题在哪?
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <title>jQuery动画特效</title> <script> $(function(){ $("body").append("<button id='you'>右移动50PX</button>"), $("body").append("<button id='zuo'>左移动50PX</button>"), $("body").append("<div>这是一段可以移动的文字</div>") }); $("div").css({"background-color":"red","color":"white","text-align":"center"}); $("#you").bind("click",function(){$("div").animate({left: "+=100px"},2000)}); $("#zuo").bind("click",function(){$("div").animate({right: "+=100px"},2000)}); </script> </head> <body> </body> </html>
修改过后无法实现居中显示还有无法实现移动效果?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<title>jQuery动画特效</title>
<script>
$(function(){
$("body").append("<button id='you'>右移动50PX</button>"),
$("body").append("<button id='zuo'>左移动50PX</button>"),
$("body").append("<div>这是一段可以移动的文字</div>")
$("body").css({"margin":"20 auto"});
$("div").css({"background-color":"red","color":"white","width":"300","height":"80",});
$("#you").bind("click",function(){$("div").animate({left: "+=100px"},2000,function(){})});
$("#zuo").bind("click",function(){$("div").animate({right: "+=100px"},2000,function(){})});
});
</script>
</head>
<body>
</body>
</html>