JS实现响应鼠标点击动画渐变弹出层效果代码
网络编程 2021-07-04 21:04www.168986.cn编程入门
这篇文章主要介绍了JS实现响应鼠标点击动画渐变弹出层效果代码,具有非常自然流畅的动画过度效果,涉及JavaScript针对鼠标事件的响应及页面元素样式的动态操作相关技巧,需要的朋友可以参考下
本文实例讲述了JS实现响应鼠标点击动画渐变弹出层效果。分享给大家供大家参考,具体如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>动画弹出层</title> <style> .list{ position:relative;; background:#eee; border:1px #c solid; margin:10px; height:30px; width:100px; cursor :pointer ; } .listShow{ position:relative; background:#eff; border:1px #ddd solid; margin:10px; height:30px; width:100px; cursor :pointer ; } .ment{ position:absolute; left:0; display:none; position:absolute; border:1px #c solid; background:#fee; width:200px; height:200px; overflow:hidden; z-index:100; } </style> </head> <body> <div class="" id="show"> 0 </div> <div class="list" id="list1">1 <div class="ment" id="ment1">狼蚁SEO<br/> </div> <div class="list" id="list2">2 <div class="ment" id="ment2">新浪搜狐</div> </div> <div class="list" id="list3">3 <div class="ment" id="ment3">网页特效</div> </div> </body> </html> <script> var zindex=0; function $id(id){ return document.getElementById(id); } var Bind = function(object,fun){ var args = Array.prototype.slice.call(arguments).slice(2); return function(){ return fun.apply(object,args); } } function addEventHandler(oTarget, sEventType, fnHandler){ if(oTarget.addEventListener){oTarget.addEventListener(sEventType, fnHandler, false);} else if(oTarget.attachEvent){oTarget.attachEvent('on' + sEventType, fnHandler);} else{oTarget['on' + sEventType] = fnHandler;} } var Shower=function(){ this.list=null; this.ment=null; this.moveLeft=80; this.moveTop=20; this.height=150; this.width=250; this.time=800; this.init=function(lisObj,Obj){ this.list=lisObj; this.ment=Obj; var _this=this; this._fnMove=Bind(this,this.move); (function(){ var obj=_this; addEventHandler(obj.list,"click",obj._fnMove); })(); }; this.move=function(){ var _this=this; var w=0; var h=0; var height=0; //弹出div的高 var width=0; //弹出div的宽 var t=0; var startTime = new Date().getTime();//开始执行的时间 if(!_this.ment.style.display||_this.ment.style.display=="none"){ _this.ment.style.display="block"; _this.ment.style.height=0+"px"; _this.ment.style.width=0+"px"; _this.list.style.zIndex=++zindex; _this.list.className="listShow"; var ment=_this.ment.innerHTML; _this.ment.innerHTML=""; //去掉显示内容 var timer=setInterval(function(){ var newTime = new Date().getTime(); var timestamp = newTime - startTime; _this.ment.style.left=Math.ceil(w)+"px"; _this.ment.style.=Math.ceil(h)+"px"; _this.ment.style.height=height+"px"; _this.ment.style.width=width+"px"; t++; var change=(Math.pow((timestamp/_this.time-1), 3) +1); //根据运行时间得到基础变化量 w=_this.moveLeftchange; h=_this.moveTopchange; height=_this.heightchange; width=_this.widthchange; $id("show").innerHTML=w; if(w>_this.moveLeft){ clearInterval(timer); _this.ment.style.left=_this.moveLeft+"px"; _this.ment.style.=_this.moveTop+"px"; _this.ment.style.height=_this.height+"px"; _this.ment.style.width=_this.width+"px"; _this.ment.innerHTML=ment; //回复显示内容 } },1,_this.ment); }else{ _this.hidden(); } } this.hidden=function(){ var _this=this; var flag=1; var hiddenTimer=setInterval(function(){ if(flag==1){ _this.ment.style.height=parseInt(_this.ment.style.height)-10+"px"; }else{ _this.ment.style.width=parseInt(_this.ment.style.width)-15+"px"; _this.ment.style.left=parseInt(_this.ment.style.left)+5+"px"; } if(flag==1 && parseInt(_this.ment.style.height)<10){ flag=-flag; } if(parseInt(_this.ment.style.width)<20){ clearInterval(hiddenTimer); _this.ment.style.left="0px"; _this.ment.style.="0px"; _this.ment.style.height="0px"; _this.ment.style.width="0px"; _this.ment.style.display="none"; if(_this.list.style.zIndex==zindex){ zindex--; }; _this.list.style.zIndex=0; _this.list.className="list"; } },1) } } window.onload=function(){ //建立各个菜单对象 var shower1=new Shower(); shower1.init($id("list1"),$id("ment1")); var shower2=new Shower(); shower2.init($id("list2"),$id("ment2")); var shower3=new Shower(); shower3.init($id("list3"),$id("ment3")); } </script>
更多关于JavaScript相关内容感兴趣的读者可查看本站专题《》、《》、《》、《》、《》及《》
希望本文所述对大家JavaScript程序设计有所帮助。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指