JS模拟酷狗音乐播放器收缩折叠关闭效果代码
网络编程 2021-07-04 21:03www.168986.cn编程入门
这篇文章主要介绍了JS模拟酷狗音乐播放器收缩折叠关闭效果代码,涉及JavaScript响应鼠标事件控制页面元素样式变换的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了JS模拟酷狗音乐播放器收缩折叠关闭效果代码。分享给大家供大家参考,具体如下
这是一款模拟酷狗音乐播放器的关闭特效,采用JavaScript实现,关闭的时候播放界面缩成一条线,然后消失,就像有些电视机突然停电的效果,很有意思的网页动画特效。
运行效果截图如下
在线演示地址如下
具体代码如下
<!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>酷狗音乐播放器的关闭特效,采用JavaScript实现</title> <style type="text/css"> { padding:0px; margin:0px; } #outer { width:952px; height: 640px; position:absolute; left:100px; :20px; } #div1 { width:952px; height: 640px; overflow:hidden; position:absolute;font-size:0px; } #div1 a { position:absolute; width:23px; height:21px; right:5px; :5px; display:block; z-index:100; background:url(images/kugou.jpg) no-repeat 957px 645px;} #div1 a:hover { background:url(images/hover.jpg) no-repeat right ; } #line { height:3px; width:952px; display:none; z-index:100; position:absolute; left:0px; :0px; font-size:0px; } #light{ /width:50px; height:10px;/ position:absolute; left:50%; :50%;/ margin-left:-25px; margin-:-5px;/ width:0px; height:0px; filter:alpha(opacity:0);opacity:0;); overflow:hidden;} </style> <script type="text/javascript"> function css(obj, attr, value) { if(arguments.length==2) { if(attr!='opacity') { return parseInt(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr]); } else { return Math.round(100parseFloat(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr])); } } else if(arguments.length==3) switch(attr) { case 'width': case 'height': case 'paddingLeft': case 'paddingTop': case 'paddingRight': case 'paddingBottom': value=Math.max(value,0); case 'left': case '': case 'marginLeft': case 'marginTop': case 'marginRight': case 'marginBottom': obj.style[attr]=value+'px'; break; case 'opacity': obj.style.filter="alpha(opacity:"+value+")"; obj.style.opacity=value/100; break; default: obj.style[attr]=value; } return function (attr_in, value_in){css(obj, attr_in, value_in)}; } var MIAOV_MOVE_TYPE={ BUFFER: 1, FLEX: 2 };//json function miaovSMove(obj) { clearInterval(obj.timer); } function miaovStartMove(obj, oTarget,iSpeedCtrol, iType, fnCallBack, fnDuring) { var fnMove=null; if(obj.timer) { clearInterval(obj.timer); } switch(iType) { case MIAOV_MOVE_TYPE.BUFFER: fnMove=miaovDoMoveBuffer; break; case MIAOV_MOVE_TYPE.FLEX: fnMove=miaovDoMoveFlex; break; } obj.timer=setInterval(function (){ fnMove(obj, oTarget,iSpeedCtrol, fnCallBack, fnDuring); }, 30); } function miaovDoMoveBuffer(obj, oTarget,iSpeedCtrol, fnCallBack, fnDuring) { var bS=true; var attr=''; var speed=0; var cur=0; for(attr in oTarget) { cur=css(obj, attr); if(oTarget[attr]!=cur) { bS=false; speed=(oTarget[attr]-cur)/iSpeedCtrol; speed=speed>0?Math.ceil(speed):Math.floor(speed); css(obj, attr, cur+speed); } } if(fnDuring)fnDuring.call(obj); if(bS) { clearInterval(obj.timer); obj.timer=null; if(fnCallBack)fnCallBack.call(obj); } } function miaovDoMoveFlex(obj, oTarget,iSpeedCtrol, fnCallBack, fnDuring) { var bS=true; var attr=''; var speed=0; var cur=0; for(attr in oTarget) { if(!obj.oSpeed)obj.oSpeed={}; if(!obj.oSpeed[attr])obj.oSpeed[attr]=0; cur=css(obj, attr); if(Math.abs(oTarget[attr]-cur)>=1 || Math.abs(obj.oSpeed[attr])>=1) { bS=false; obj.oSpeed[attr]+=(oTarget[attr]-cur)/iSpeedCtrol; obj.oSpeed[attr]=0.7; css(obj, attr, cur+obj.oSpeed[attr]); } } if(fnDuring)fnDuring.call(obj); if(bS) { clearInterval(obj.timer); obj.timer=null; if(fnCallBack)fnCallBack.call(obj); } } </script> <script type="text/javascript"> window.onload=function(){ var oDiv1 = document.getElementById('div1'); var oAbtn = oDiv1.getElementsByTagName('a')[0]; var oImg1 = document.getElementById('img1'); var oImg2 = document.getElementById('img2'); var oImg3 = document.getElementById('img3'); var oLine = document.getElementById('line'); var oLight = document.getElementById('light'); oAbtn.onclick=function(){ miaovStartMove(oDiv1, {height:3,marginTop:315},1.5, MIAOV_MOVE_TYPE.BUFFER,function(){ oImg1.style.display='none'; oLine.style.display='block'; miaovStartMove(oDiv1, {width:0,marginLeft:476},2, MIAOV_MOVE_TYPE.BUFFER); miaovStartMove(oLine, {width:0},2, MIAOV_MOVE_TYPE.BUFFER); miaovStartMove(oImg2, {width:0},2, MIAOV_MOVE_TYPE.BUFFER,function(){ miaovStartMove(oImg3, {width:200,height:10},1, MIAOV_MOVE_TYPE.BUFFER); miaovStartMove(oLight, {width:200,height:10,marginLeft:-100,marginTop:-5,opacity:100},1, MIAOV_MOVE_TYPE.BUFFER,function(){ miaovStartMove(oLight, {opacity:0},1, MIAOV_MOVE_TYPE.BUFFER); }); }); }); } } </script> </head> <body> <div id="outer"> <div id="light"><img id="img3" src="images/line1.png" style="width:0px; height:0px;"/></div> <div id="div1"> <img id="img1" src="images/kugou.jpg" style="height:640px; width:952px; z-index:-3;"/> <a href="#"></a> <div id="line"> <img id="img2" src="images/line.png" style=" width:952px; height:3px;" /> </div> </div> </div> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程