实现效果:当鼠标移动上去时,div逐渐变慢的移除;当鼠标离开时,又逐渐变慢的恢复原位置。

代码:
S-CMS政府建站系统是淄博闪灵网络科技有限公司开发的一款专门为企业建站提供解决方案的产品,前端模板样式主打HTML5模板,以动画效果好、页面流畅、响应式布局为特色,程序主体采用ASP+ACCESS/MSSQL构架,拥有独立自主开发的一整套函数、标签系统,具有极强的可扩展性,设计师可以非常简单的开发出漂亮实用的模板。系统自2015年发布第一个版本以来,至今已积累上万用户群,为上万企业提供最优质的建
258
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>缓冲动画</title>
<style type="text/css">
body,div,span{
margin:0;
padding;
}
#div1{
width:200px;
height:200px;
background:red;
position:relative;
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 = function(){
startMove(0);
}
oDiv.onmouseout = function(){
startMove(-200);
}
}
var timer = null;
// 参数iTarget,设置DIV移动的边界。
// 取消由 setInterval()设置的每一次触发鼠标事件。
// 设置DIV的运动。
function startMove(iTarget){
clearInterval(timer);
var oDiv = document.getElementById('div1');
timer = setInterval(function(){
var speed = (iTarget - oDiv.offsetLeft)/20;
speed = speed > 0?Math.ceil(speed):Math.floor(speed);
if(oDiv.offsetLeft == iTarget){
clearInterval(timer);
}else{
oDiv.style.left = oDiv.offsetLeft+speed+'px';
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="share">分享</span>
</div>
</body>
</html> 以上就是前端实践--JavaScript--动画(三)的内容,更多相关内容请关注PHP中文网(www.php.cn)!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号