首頁 > web前端 > js教程 > JS模擬酷狗音樂播放器收縮折疊關閉效果代碼_javascript技巧

JS模擬酷狗音樂播放器收縮折疊關閉效果代碼_javascript技巧

WBOY
發布: 2016-05-16 15:34:30
原創
1847 人瀏覽過

本文實例講述了JS模擬酷狗音樂播放器收縮折疊關閉效果代碼。分享給大家參考,具體如下:

這是一款模擬酷狗音樂播放器的關閉特效,採用JavaScript實現,關閉的時候播放界面縮成一條線,然後消失,就像有些電視機突然停電的效果,很有意思的網頁動畫特效。

運作效果截圖如下:

線上示範網址如下:

http://demo.jb51.net/js/2015/js-kugou-music-player-style-demo/

具體程式碼如下:

<!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=utf-8" />
<title>酷狗音乐播放器的关闭特效,采用JavaScript实现</title>
<style type="text/css">
* {
 padding:0px;
 margin:0px;
}
#outer {
 width:952px;
 height: 640px;
 position:absolute;
 left:100px;
 top:20px; }
#div1 {
 width:952px;
 height: 640px;
 overflow:hidden; 
 position:absolute;font-size:0px;
}
#div1 a {
 position:absolute;
 width:23px;
 height:21px;
 right:5px;
 top: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 top;
}
#line {
 height:3px;
 width:952px;
 display:none;
 z-index:100;
 position:absolute;
 left:0px;
 top:0px; font-size:0px;
}
#light{ /*width:50px; height:10px;*/ position:absolute; left:50%; top:50%;/* margin-left:-25px; margin-top:-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&#63;obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr]);
  }
  else
  {
   return Math.round(100*parseFloat(obj.currentStyle&#63;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 'top':
   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 miaovStopMove(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 bStop=true;
 var attr='';
 var speed=0;
 var cur=0;
 for(attr in oTarget)
 {
  cur=css(obj, attr);
  if(oTarget[attr]!=cur)
  {
   bStop=false;
   speed=(oTarget[attr]-cur)/iSpeedCtrol;
   speed=speed>0&#63;Math.ceil(speed):Math.floor(speed);
   css(obj, attr, cur+speed);
  }
 }
 if(fnDuring)fnDuring.call(obj);
 if(bStop)
 {
  clearInterval(obj.timer);
  obj.timer=null;
  if(fnCallBack)fnCallBack.call(obj);
 }
}
function miaovDoMoveFlex(obj, oTarget,iSpeedCtrol, fnCallBack, fnDuring)
{
 var bStop=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)
  {
   bStop=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(bStop)
 {
  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程式設計有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板