position 改成 relative 便會一直運動?
為什么 id div1的position屬性改成“relative”就會一直動下去不會停止,而改成“absolute”就可以停止呢?
? ? ??
#div1
? ? ??
{
? ? ? ? ??
width:200px;
? ? ? ? ??
height:200px;
? ? ? ? ??
background:red;
? ? ? ? ??
position:absolute;? //改成relative就會一直動?
? ? ? ? ??
left:-200px;
? ? ? ? ??
top:0
? ? ??
}
2016-03-09
同學(xué),我也遇到這個問題,視頻07:03秒的時候老師的#div1{ position:relative}竟然可以運行成功,而我的就只能改成absolute才能成功,問題到底出在哪里呢?
2016-03-09
relative是相對自身偏移,當(dāng)然會一直運動下去,詳情再去看一下relative解析
2016-03-03
<!DOCTYPE html>
<html>
<head lang="en">
? ?<meta charset="UTF-8">
? ?<title></title>
? ?<style>
? ? ? ?#div1
{
? ? ? ? ? ?width:200px;
? ? ? ? ? ?height:200px;
? ? ? ? ? ?background:red;
? ? ? ? ? ?position:absolute;
? ? ? ? ? ?left:-200px;
? ? ? ? ? ?top:0
}
? ? ? ?#div1 span
{
? ? ? ?width:20px;
? ? ? ?height:50px;
? ? ? ?background:blue;
? ? ? ?position:absolute;
? ? ? ?left:200px;
? ? ? ?top:75px;
? ? ? ?}
? ? ? ?</style>
<script>
? ?window.onload=function() {
? ? ? ?var oDiv = document.getElementById("div1");
? ? ? ?oDiv.onmouseover = startMove;
? ?};
? ?var timer=null;
? ?function startMove()
? ?{
? ? ? ?var oDiv = document.getElementById("div1");
? ? ? ?clearInterval(timer);
? ? ? ?timer=setInterval(function()
? ? ? ?{
? ? ? ? ? ?if(oDiv.offsetLeft==0)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?clearInterval(timer);
? ? ? ? ? ?}
? ? ? ? ? ?else
{
? ? ? ? ? ? ? ?oDiv.style.left = oDiv.offsetLeft + 10 + 'px';
? ? ? ? ? ?}
? ? ? ?},10)
? ?}
</script>
</head>
<body>
? ?<div id="div1"><span id="share">分享</span></div>
</body>
</html>
2016-03-03
源碼呢?你肯定是寫了JS 動效吧!