JavaScript仿flash遮罩動(dòng)畫(huà)效果
本文實(shí)例為大家分享了JavaScript仿flash遮罩動(dòng)畫(huà)的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>仿flash遮罩動(dòng)畫(huà)</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個(gè)參數(shù)和第5個(gè)參數(shù)分別設(shè)置20和2效果會(huì)比較好
//第5個(gè)參數(shù)必須是偶數(shù)
});
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)JavaScript程序設(shè)計(jì)有所幫助。
- js實(shí)現(xiàn)鼠標(biāo)移動(dòng)到圖片產(chǎn)生遮罩效果
- js+html5實(shí)現(xiàn)半透明遮罩層彈框效果
- js遮罩效果制作彈出注冊(cè)界面效果
- JavaScript編寫(xiě)頁(yè)面半透明遮罩效果的簡(jiǎn)單示例
- 使用CSS+JavaScript或純js實(shí)現(xiàn)半透明遮罩效果的實(shí)例分享
- 基于JavaScript實(shí)現(xiàn)全屏透明遮罩div層鎖屏效果
- js點(diǎn)擊按鈕實(shí)現(xiàn)帶遮罩層的彈出視頻效果
- js彈窗返回值詳解(window.open方式)
- js彈出框、對(duì)話框、提示框、彈窗實(shí)現(xiàn)方法總結(jié)(推薦)
- JS使用遮罩實(shí)現(xiàn)點(diǎn)擊某區(qū)域以外時(shí)彈窗的彈出與關(guān)閉功能示例
相關(guān)文章
window.print()局部打印三種方式(小結(jié))
本文主要介紹了window.print()局部打印三種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
js屏蔽鼠標(biāo)鍵盤(pán)(右鍵/Ctrl+N/Shift+F10/F11/F5刷新/退格鍵)
屏蔽鼠標(biāo)右鍵、Ctrl+N、Shift+F10、F11、F5刷新、退格鍵/Alt+ 方向鍵 →等等,太多了就不一一寫(xiě)來(lái)了感興趣的朋友可以了解下啊,希望本文對(duì)你有所幫助2013-01-01
JS實(shí)現(xiàn)圖片元素轉(zhuǎn)BASE64編碼的簡(jiǎn)單示例
在Web開(kāi)發(fā)中,我們經(jīng)常需要將圖片轉(zhuǎn)換為Base64格式,以便在不依賴外部資源的情況下直接在HTML中使用,在這篇文章中,我將向您展示如何使用JavaScript將圖片元素轉(zhuǎn)BASE64編碼,需要的朋友可以參考下2023-12-12
微信小程序之 catalog 切換實(shí)現(xiàn)解析
這篇文章主要介紹了微信小程序之 catalog 切換實(shí)現(xiàn)解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
Three.js如何用軌跡球插件(trackball)增加對(duì)模型的交互功能詳解
這篇文章主要給大家介紹了關(guān)于Three.js如何用軌跡球插件,也就是trackball增加對(duì)模型的交互功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-09-09
利用Math.js解決JS計(jì)算小數(shù)精度丟失問(wèn)題
電商系統(tǒng)中訂單、庫(kù)存中有數(shù)字等加減乘除算術(shù),下面這篇文章主要給大家介紹了關(guān)于利用Math.js解決JS計(jì)算小數(shù)精度丟失問(wèn)題的相關(guān)資料,mathjs是一個(gè)前端在計(jì)算上面必定會(huì)用到的類庫(kù),需要的朋友可以參考下2022-04-04
js立即執(zhí)行函數(shù): (function ( ){})( ) 與 (function ( ){}( )) 有什么區(qū)別?
這篇文章主要介紹了js立即執(zhí)行函數(shù): (function ( ){})( ) 與 (function ( ){}( )) 有什么區(qū)別,需要的朋友可以參考下2015-11-11
JavaScript倒計(jì)時(shí)定時(shí)器和間隔定時(shí)器使用詳解
這篇文章主要為大家介紹了JavaScript倒計(jì)時(shí)定時(shí)器和間隔定時(shí)器使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>2023-05-05

