您好,欢迎来到尚佳旅游分享网。
搜索
您的当前位置:首页jQuery实现的鼠标响应缓冲动画效果

jQuery实现的鼠标响应缓冲动画效果

来源:尚佳旅游分享网
这篇文章主要介绍了jQuery实现的鼠标响应缓冲动画效果,涉及jQuery事件响应、数值运算及页面元素动态操作相关技巧,需要的朋友可以参考下

本文实例讲述了jQuery实现的鼠标响应缓冲动画效果。分享给大家供大家参考,具体如下:

先来看看运行效果:

具体代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>js动画-缓冲动画</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.js"></script>
<style>
* {
 margin: 0;
 padding: 0;
 font-family:"微软雅黑"
}
#box{
 height:100px;
 width:100px;
 background-color:#0099CC;
 margin-top:200px;
 position:relative;
 /*速速、缓冲变化*/
 left:-100px;
}
span{
 display:block;
 color:blue;
 width:25px;
 height:100px;
 background-color:#FFFF99;
 position:absolute;
 left:100px;
}
</style>
</head>
<body>
 <p id="box">
 <span>移动</span>
 </p>
<script>
window.onload=function(){
 var p1=document.getElementById("box");
 p1.onmouseover=function(){
 startMove(0);
 }
 p1.onmouseout=function(){
 startMove(-100);
 }
}
var timer=null;
function startMove(itarget){
 clearInterval(timer);
 var p1=document.getElementById("box");
 timer=setInterval(function(){
 var speed=(itarget-p1.offsetLeft)/20;
 speed=speed>0?Math.ceil(speed):Math.floor(speed);
 if(p1.offsetLeft==itarget){
 clearInterval(timer);
 }else{
 p1.style.left=p1.offsetLeft+speed+"px";
 }
 },30)
}
</script>
</body>
</html>

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

如何在vue2中设置全局变量?(详细教程)

根据vue里面设置全局变量或者数据方法(详细教程)

如何在JS中实现字符串拼接的功能(扩展String.prototype.format)

Copyright © 2019- shangjiatang.cn 版权所有 湘ICP备2022005869号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务