js实现框架内图层轨迹运动效果

3个月前 (02-21 14:19)阅读73回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值4189
  • 级别管理员
  • 主题837
  • 回复2
楼主

js代码实现图层在框架内按轨迹运动效果,可根据鼠标运动轨迹来回移动,又是一款图层轨迹移动js特效。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js实现框架内图层运动效果_武鸣人</title>
<meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren">
<meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。">
<style> 
body,div{margin:0;padding:0;}
#www_wuming_ren{width:500px;margin:10px auto;}
.box_www_wuming_ren{position:relative;height:100px;border:1px solid #666;margin-top:10px;}
.box_www_wuming_ren span{position:absolute;top:10px;left:10px;width:20px;height:20px;background:#999;display:block;opacity:1;}
</style>
<script type="text/javascript"> 
//面向对象版运动框架
var Animate = function (oElement, options, callback) {this.initialize.apply(this, arguments)};
//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
Animate.prototype = {
initialize: function (oElement, options, callback)
{
var oThis = this;
this.options = options;
this.callback = callback;
this.oElement = typeof oElement === "string" ? document.getElementById(oElement) : oElement;
clearInterval(this.timer);
this.timer = setInterval(function ()
{
oThis.doMove()
}, 30)
},
css: function (attr, value)
{
if (arguments.length == 1)
{
return parseFloat(this.oElement.currentStyle ? this.oElement.currentStyle[attr] : getComputedStyle(this.oElement, null)[attr])
}
else if (arguments.length == 2)
{
attr == "opacity" ? (this.oElement.style.filter = "alpha(opacity=" + value + ")", this.oElement.style.opacity = value / 100) : this.oElement.style[attr] = value + "px"
}
},
doMove: function ()
{
var opt = this.options;
var bComplete = true;
for (var p in opt)
{
var iCur = p == "opacity" ? parseInt(this.css(p).toFixed(2) * 100) : this.css(p);
var iSpeed = (opt[p] - iCur) / 5;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
opt[p] == iCur || (bComplete = false, this.css(p, iCur + iSpeed))
}
bComplete && (clearInterval(this.timer), this.callback && this.callback.call(this))
}
};//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
//运动框架应用
window.onload = function ()
{
var oSpan = document.getElementsByTagName("span")[0];
var oInput = document.getElementsByTagName("input")[0];
//定义运动路径
var aData = [
{width:20, height:20},
{width:80, height:80},
{left:10}, {left:408},
{opacity:100},
{opacity:0},
{opacity:100},
{width:80, height:80, left:408},
{top:10},
{width:20, height:20, left:468},
{top:70},
{left:10},
{top:10},
{left:468},
{width:20, height:20, left:468},
{width:80, height:80, left:408}
];
var bOrder = true;
var i = 0;
oInput.disabled = false;
//按钮点击事件(开始/返回)
oInput.onclick = function ()
{
var oThis = this;
oThis.disabled = true;
function begin()
{
bOrder ? i++ : i--;
var obj = new Animate(oSpan, aData[i], begin);
if (i == aData.length || i < 0)
{
clearInterval(obj.timer);
bOrder = !bOrder;
oThis.value = bOrder ? "\u5f00\u59cb" : "\u539f\u8def\u8fd4\u56de";
oThis.disabled = false;
return
}
}
begin()
};
//去除按钮虚线
oInput.onfocus = function ()
{
this.blur();
}
}
</script>
</head>
<body>
<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<div id="www_wuming_ren">
    <input type="button" value="开始" />
    <div class="box_www_wuming_ren"><span></span></div>
</div>
</body>
</html>


0
0
收藏0
回帖

js实现框架内图层轨迹运动效果 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息