animate点击按钮变大并以元素中心向外变大
程序员文章站
2022-03-16 18:58:16
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.box{
width:100px;
height:100px;
margin:200px 200px;
border-radius:10px;
box-shadow: 0 0 20px #999;
line-height: 300px;
text-align: center;
font-size: 50px;
color:#fff;
}
#box1{
background:#5298c7;
}
</style>
</head>
<body>
<div id="box1" class="box"></div>
<script src="../js/jquery-1.12.4.js"></script>
<script>
$('#box1').click(function () {
var $this=$(this);
$this.css({
position:'absolute',
//获得当前已定位元素的top值
top:$this.position().top,
left:$this.position().left
})
.animate({
//获得当前元素的宽度并*2
width:$this.width()*2,
height:$this.height()*2,
top:$this.position().top-$this.height(),
left:$this.position().left-$this.width()
},500)
})
</script>
</body>
</html>