如何在Jquery动画函数中使用随机值? [英] How to use random value in Jquery animate function?
本文介绍了如何在Jquery动画函数中使用随机值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个滑块div,它使用Jquery(动画函数)在html文档上移动随机位置。
我的HTML代码是: -
I want to create a slider div which move random position on the html documents with Jquery (animate function).
My HTML code is :-
<html>
<head>
<script src="scripts/jquery-1.8.3.min.js">
</script>
<script>
$(document).ready(function(){
$("#bu1").click(function(){
var temp=parseInt(Math.random()* document.body.clientWidth);
temp="'"+temp+"px'";
$("div").animate({left:temp});
});
});
</script>
</head>
<body>
<button id="bu1">Start Animation</button>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>
</body>
</html>
when我运行它不会移动那个div ...
如何在CSS中写出 Math.Random
值???? br />
感谢高级..
when I run this its doesn''t move that div ...
how to write that Math.Random
value in CSS ????
thanks in advanced..
推荐答案
( document ).ready( function (){
(document).ready(function(){
( # bu1)。click( function (){
var temp = < span class =code-sdkkeyword> parseInt ( Math .random()* document .body.clientWidth);
temp = ' + temp + px';
("#bu1").click(function(){ var temp=parseInt(Math.random()* document.body.clientWidth); temp="'"+temp+"px'";
( < span class =code-string> div)。animate({left:temp});
});
});
< / script >
< / head >
< 正文 >
< 按钮 id = bu1 > 开始动画< / button >
< ; div style = background:#98bf21; height:100px; width:100px; position:absolute; >
< / div >
< / body >
< / html >
("div").animate({left:temp}); }); }); </script> </head> <body> <button id="bu1">Start Animation</button> <div style="background:#98bf21;height:100px;width:100px;position:absolute;"> </div> </body> </html>
when我运行它不会移动那个div ...
如何在CSS中写出 Math.Random
值???? br />
感谢先进..
when I run this its doesn''t move that div ...
how to write that Math.Random
value in CSS ????
thanks in advanced..
这篇关于如何在Jquery动画函数中使用随机值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文