国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript仿flash遮罩動畫效果

2019-11-20 09:41:54
字體:
來源:轉載
供稿:網友

本文實例為大家分享了JavaScript仿flash遮罩動畫的具體實現代碼,供大家參考,具體內容如下

<!DOCTYPE html><html><head><meta charset="utf-8"><title>仿flash遮罩動畫</title><meta name="keywords" content=""><meta name="description" content=""><script charset="utf-8" src="jquery.js"></script><style media="screen">body{margin:0;}#banner{position:relative;width:858px;height:238px;overflow:hidden;}</style></head><body><div id="banner">  <a href="javascript:void(0);"><img src="1.jpg" width="858" height="238"/></a></div><script type="text/javascript">function setMaskingAnimation(container,width,height,time,pixel,color){  var __left=mtRand(parseInt(width*0.25),parseInt(width*0.75));  var __top=mtRand(parseInt(height*0.25),parseInt(height*0.75));  if(width>=height){    var widthSpeed=parseInt((width/height)*10);    var heightSpeed=10;    var __width=widthSpeed;    var __height=heightSpeed;  }  else{    var widthSpeed=10;    var heightSpeed=parseInt((height/width)*10);    var __width=widthSpeed;    var __height=heightSpeed;  }  var hander;  //  function getPosition(_width,_height,_left,_top){    var div1={      "width":_left,      "height":_top,      "left":0,      "top":0    };    var div2={      "width":_width,      "height":_top,      "left":_left,      "top":0    };    var div3={      "width":width-_left-_width,      "height":_top,      "left":_left+_width,      "top":0    };    var div4={      "width":_left,      "height":_height,      "left":0,      "top":_top    };    var div5={      "width":_width,      "height":_height,      "left":_left,      "top":_top    };    var div6={      "width":width-_left-_width,      "height":_height,      "left":_left+_width,      "top":_top    };    var div7={      "width":_left,      "height":height-_top-_height,      "left":0,      "top":_top+_height    };    var div8={      "width":_width,      "height":height-_top-_height,      "left":_left,      "top":_top+_height    };    var div9={      "width":width-_left-_width,      "height":height-_top-_height,      "left":_left+_width,      "top":_top+_height    };    return {      "div1":div1,      "div2":div2,      "div3":div3,      "div4":div4,      "div5":div5,      "div6":div6,      "div7":div7,      "div8":div8,      "div9":div9,    };  }  //  function mtRand(n1,n2){    return parseInt(Math.random()*(n2-n1+1)+n1);  }  //  function setDiv(i,position){    var has=$(container).find("div.mask"+i);    if(has.length){      has.css("left",position.left);      has.css("top",position.top);      has.css("width",position.width);      has.css("height",position.height);    }    else{      var html='<div class="mask mask{@i}" style="position:absolute;left:{@left}px;top:{@top}px;width:{@width}px;height:{@height}px;background-color:{@backgroundColor};"></div>';      html=html.replace('{@i}',i);      html=html.replace('{@left}',position.left);      html=html.replace('{@top}',position.top);      html=html.replace('{@width}',position.width);      html=html.replace('{@height}',position.height);      if(i==5){        html=html.replace('{@backgroundColor}',"transparent");      }      else{        html=html.replace('{@backgroundColor}',color);      }      $(container).append(html);    }  }  //  function play(){    __width+=pixel*widthSpeed;    __height+=pixel*heightSpeed;    __left-=pixel*widthSpeed/2;    __top-=pixel*heightSpeed/2;    var position=getPosition(__width,__height,__left,__top);    for(var i=1;i<=9;i++){      setDiv(i,position["div"+i]);    }    if(position.div1.width<=0 && position.div1.height<=0 && position.div9.width<=0 && position.div9.height<=0){      window.clearInterval(hander);      $(container).find("div.mask").remove();    }  }  //  hander=window.setInterval(play,time);} $(function(){  setMaskingAnimation("#banner",858,238,100,2,"#ff0000");  //第4個參數和第5個參數分別設置20和2效果會比較好  //第5個參數必須是偶數});</script></body></html>

以上就是本文的全部內容,希望對大家學習JavaScript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苏州市| 梓潼县| 锡林浩特市| 玉林市| 会泽县| 呈贡县| 鹤山市| 开化县| 新龙县| 乌兰察布市| 赤水市| 六枝特区| 慈溪市| 左贡县| 特克斯县| 逊克县| 延边| 南召县| 蒲城县| 岐山县| 南丹县| 崇礼县| 进贤县| 南阳市| 康马县| 都兰县| 东辽县| 无锡市| 河曲县| 鄂尔多斯市| 璧山县| 建阳市| 潜山县| 吴忠市| 七台河市| 顺昌县| 阿拉善左旗| 淅川县| 衢州市| 松阳县| 密山市|