纵向展开
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 100px;
height: 100px;
background: rgb(9, 175, 9);
position: fixed;
top: 100px;
left: 0px;
overflow: hidden;
}
button{
height: 30px;
width: 50px;
margin: 30px;
}
</style>
</head>
<body>
<button>点击</button>
<div>
</div>
<script>
var oBtn=document.querySelector('button');
var oDiv=document.querySelector('div');
oBtn.addEventListener('click',function(){
var speed=0;
var time=setInterval(function(){
speed+=10;
oDiv.style.height=speed+'px';
if(speed==600){
clearInterval(time);
}
},30)
})
<script>
横向展开
var oBtn=document.querySelector('button');
var oDiv=document.querySelector('div');
oBtn.addEventListener('click',function(){
var speed=0;
var time=setInterval(function(){
speed+=10;
oDiv.style.width=speed+'px';
if(speed==500){
clearInterval(time);
}
},30)
})
斜向展开
var oBtn = document.querySelector('button');
var oDiv = document.querySelector('div');
oBtn.addEventListener('click' , function(){
var speed = 0;
var time = setInterval(function(){
speed += 10;
oDiv.style.width= speed + 'px';
oDiv.style.height= speed + 'px';
if(speed == 500){
clearInterval(time);
}
} , 30)
})
水平移动
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 100px;
height: 100px;
background: rgb(9, 175, 9);
position: fixed;
top: 100px;
left: 0px;
overflow: hidden;
margin-left: 30px;
}
button{
height: 30px;
width: 50px;
margin: 30px;
}
</style>
</head>
<body>
<button>点击</button>
<div>
</div>
<script>
var oBtn = document.querySelector('button');
var oDiv = document.querySelector('div');
oBtn.addEventListener('click' , function(){
var speed = 0;
var time = setInterval(function(){
speed += 10;
oDiv.style.left = speed + 'px';
if(speed == 500){
clearInterval(time);
}
} , 30)
})
</script>
纵向移动
var oBtn=document.querySelector('button');
var oDiv=document.querySelector('div');
oBtn.addEventListener('click',function(){
var speed=0;
var time=setInterval(function(){
speed+=20;
oDiv.style.top=speed+'px';
if(speed==500){
clearInterval(time);
}
},30)
})
斜向移动
var oBtn=document.querySelector('button');
var oDiv=document.querySelector('div');
oBtn.addEventListener('click',function(){
var speed=0;
var time=setInterval(function(){
speed+=20;
oDiv.style.top=speed+'px';
oDiv.style.left=speed+'px';
if(speed==500){
clearInterval(time);
}
},30)
})