如何循环我的功能以达到预期的效果? [英] How do I loop my function to achieve the desired effect?
本文介绍了如何循环我的功能以达到预期的效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是初学者,我想让这个方形的ocilate每次增加50px,直到它达到一组#of像素。
< html >
< head >
< script src = http://ajax.googleapis.com/ajax/libs/jquery/ 1.11.1 / jquery.min.js > < / script >
< script >
$(文档)。ready( function ( ){
$( div)。animate({left:' 50px'});
$( div)。animate({left:' 0px'});
$( div)。animate({top:' 50px'});
$( div)。animate({top:' 0px'});
$( div)。animate({left:' 100px'});
$( div)。animate({left:' 0px'});
$( div)。animate({top:' 100px'});
$( div)。animate({top:' 0px'});
$( div)。animate({left:' 150px'});
$( div)。animate({left:' 0px'});
$( div)。animate({top:' 150px'});
$( div)。animate({top:' 0px'});
$( div)。animate({left:' 200px'});
$( div)。animate({left:' 0px'});
$( div)。animate({top:' 200px'});
$( div)。animate({top:' 0px'});
});
// 循环直到达到设定值
< / script >
< / head < span class =code-keyword>>
< body >
< div style = background:orange; height:100px; width:100px;已删除:绝对; >
< / div >
< / body >
< / html >
我想用一个函数达到同样的效果。
解决方案
( document )。ready( function (){
< blockquote>( div)。animate({left:' 50px'});
( div)。animate({left:' 0像素'跨度>});
I'm a beginner and I want to make this square ocilate increasing by 50px each time till it reaches a set #of pixels.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div").animate({left:'50px'});
$("div").animate({left:'0px'});
$("div").animate({top:'50px'});
$("div").animate({top:'0px'});
$("div").animate({left:'100px'});
$("div").animate({left:'0px'});
$("div").animate({top:'100px'});
$("div").animate({top:'0px'});
$("div").animate({left:'150px'});
$("div").animate({left:'0px'});
$("div").animate({top:'150px'});
$("div").animate({top:'0px'});
$("div").animate({left:'200px'});
$("div").animate({left:'0px'});
$("div").animate({top:'200px'});
$("div").animate({top:'0px'});
});
//loop until reach set value
</script>
</head>
<body>
<div style="background:orange;height:100px;width:100px;removed:absolute;">
</div>
</body>
</html>
I want to achieve the same effect with a function.
解决方案
(document).ready(function(){
("div").animate({left:'50px'});
("div").animate({left:'0px'});
这篇关于如何循环我的功能以达到预期的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文