【发布时间】:2015-01-14 22:24:57
【问题描述】:
我想duplicate what this guy did 但不使用画布。我想在我的页面中心有一个 div 并简单地将宽度/高度/边框半径每秒增加 10 像素。这工作得很好,但由于某种原因,div 越大,它移动到右下方的次数就越多。圆并没有静止不动,它的中心位置随着它变大而改变。如何在不更改位置的情况下更改 div 的宽度/高度?
main.css
div {
background-color: green;
width: 100px;
height: 100px;
border-radius: 100px;
position:absolute;
top:50%;
left:50%;
margin-top:-50px; /* this is half the height of your div*/
margin-left:-100px; /*this is half of width of your div*/
}
index.html
<!DOCTYPE html>
<head>
<title>CircleTime</title>
<link rel="stylesheet" href="main.css"></link>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div></div>
</body>
</html>
app.coffee
incrementCircle = ->
newSize = circle.height() + 10
circle.height newSize
circle.width newSize
circle.css 'border-radius', newSize
$(document).ready ->
window.circle = $("div")
setInterval(incrementCircle, 1000);
【问题讨论】:
标签: javascript jquery html css