1 回答

TA貢獻1898條經驗 獲得超8個贊
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
div
{
width:100px;
height:100px;
background:red;
transition:all 5s;
}
div:hover
{
width:300px;
}
#div1{
position:relative;
width:100px;
height:100px;
}
#div2{
position:absolute;
width:100%;
height:100%;
background:#0f0;
}
#div2.div2{
width:200%;
height:200%;
}
</style>
</head>
<body>
<input type='button' id='btn1'/>
<p><b>注意:</b>該實例無法在 Internet Explorer 9 及更早 IE 版本上工作。</p>
<div></div>
<div id='div1'>
<div id='div2'></div>
</div>
<p>鼠標移動到 div 元素上,查看過渡效果。</p>
</body>
<script>
window.onload=function(){
var oBtn=document.getElementById("btn1"),oDiv=document.getElementById("div2");
oBtn.onclick=function(){
oDiv.className='div2';
}
}
</script>
</html>
給你個簡單的demo看完就會了,這也只是方法中的一種,方法還有很多!
添加回答
舉報