欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript仿flash遮罩動畫效果

 更新時間:2016年06月15日 09:27:12   作者:逍遙哥  
這篇文章主要為大家詳細介紹了JavaScript仿flash遮罩動畫效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

<!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個參數(shù)和第5個參數(shù)分別設置20和2效果會比較好
  //第5個參數(shù)必須是偶數(shù)
});
</script>
</body>
</html>

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

相關文章

  • JS實現(xiàn)的base64加密解密操作示例

    JS實現(xiàn)的base64加密解密操作示例

    這篇文章主要介紹了JS實現(xiàn)的base64加密解密操作,結(jié)合實例形式分析了基于javascript的base64加密與解密函數(shù)定義與使用相關操作技巧,需要的朋友可以參考下
    2018-04-04
  • javascript 設計模式之組合模式原理與應用詳解

    javascript 設計模式之組合模式原理與應用詳解

    這篇文章主要介紹了javascript 設計模式之組合模式原理與應用,結(jié)合實例形式分析了javascript組合模式基本概念、原理、應用場景及操作注意事項,需要的朋友可以參考下
    2020-04-04
  • TypeScript泛型使用詳細介紹

    TypeScript泛型使用詳細介紹

    泛型是靜態(tài)類型語言的基本特征,允許將類型作為參數(shù)傳遞給另一個類型、函數(shù)、或者其他結(jié)構。TypeScript 支持泛型作為將類型安全引入組件的一種方式。這些組件接受參數(shù)和返回值,其類型將是不確定的,直到它在代碼中被使用
    2022-10-10
  • Javascript中return的使用與閉包詳解

    Javascript中return的使用與閉包詳解

    Javascript中return與閉包對大家來說應該都不陌生,下面本文就給大家介紹了Javascript中return的使用與閉包。文中給出了詳細的示例代碼,對大家的理解和學習具有一定的參考借鑒價值,感興趣的朋友們下面來一起看看吧。
    2017-01-01
  • javascript定時變換圖片實例代碼

    javascript定時變換圖片實例代碼

    javascript定時變換圖片實例代碼,需要的朋友可以參考一下
    2013-03-03
  • 詳解weex默認webpack.config.js改造

    詳解weex默認webpack.config.js改造

    本篇文章主要介紹了詳解weex默認webpack.config.js改造,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • js中document.write和document.writeln的區(qū)別

    js中document.write和document.writeln的區(qū)別

    這篇文章主要介紹了js中document.write和document.writeln的區(qū)別,需要的朋友可以參考下
    2018-03-03
  • JavaScript如何將時間戳轉(zhuǎn)化為年月日時分秒格式

    JavaScript如何將時間戳轉(zhuǎn)化為年月日時分秒格式

    這篇文章主要給大家介紹了關于JavaScript如何將時間戳轉(zhuǎn)化為年月日時分秒格式的相關資料,在前端的日常工作當中,時間戳的使用也是不少的,有時后端返回給我們的數(shù)據(jù)是一個時間戳,我們需要轉(zhuǎn)換成年月日,時分秒的形式展示在頁面當中,需要的朋友可以參考下
    2023-11-11
  • window.open的頁面如何刷新(父頁面)上層頁面

    window.open的頁面如何刷新(父頁面)上層頁面

    在開發(fā)過程中會經(jīng)常遇到window.open打開的頁面,同時問題出現(xiàn)了如何刷新上層頁面呢?本文將詳細介紹,需要了解的朋友可以參考下
    2012-12-12
  • JavaScript的Number對象的toString()方法

    JavaScript的Number對象的toString()方法

    toString()方法可以把Number對象轉(zhuǎn)換成字符串,并返回此字符串,本文給大家介紹JavaScript的Number對象的toString()方法,對javascript對象方法相關知識感興趣的朋友一起學習吧
    2015-12-12

最新評論