jQuery动画一个div移动其他divs边缘(循环)

问题描述 投票:-1回答:1

我怎样才能让div围绕另一个div移动?就像移动边框一样动画移动边缘。

jquery animation move
1个回答
1
投票

尝试使用以下代码

$(document).ready(function(){
var h = $(".container").height() - $(".move").height();
var w = $(".container").width() - $(".move").width();

setInterval(function(){
$(".move").animate({left: w+'px', top:'0px'});
$(".move").animate({left: w+'px', top: h+'px'});
$(".move").animate({left: '0px', top: h+'px'});
$(".move").animate({left: '0px', top: '0px'});
},500);
});
.move {
background:#98bf21;height:50px;width:50px;position:absolute;"
}
.container { position:relative; width:500px; height:200px; border:1px solid #000;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="move"></div>
© www.soinside.com 2019 - 2024. All rights reserved.