一个类似边框弹出的小效果
<div id="box"></div>
<style> #box{ width: 300px; height: 200px; background-color: skyblue; position: absolute; left: -250px; top: 0; cursor: pointer; } </style>
<script> window.onload=function(){ var box=document.getElementById("box"); var box_left=-250; var times; var back_times; box.onmouseover=function(){ clearInterval(back_times); clearInterval(times); times=setInterval(function(){ box_left+=10; box.style.left=box_left+‘px‘; if(box_left>=0){ clearInterval(times); } },10) } box.onmouseout=function(){ clearInterval(times) clearInterval(back_times); back_times=setInterval(function(){ box_left-=10; box.style.left=box_left+‘px‘; if(box_left<=-250){ clearInterval(back_times); } },10) } } </script>
时间: 2024-10-12 15:32:57