js運(yùn)動框架_包括圖片的淡入淡出效果
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<font face="Verdana, Geneva, sans-serif"></font>
<style type="text/css">
#div1{width:100px;height:100px;background:#ccc;position:absolute;top:0px;left:0px;}
#div2{width:100px;height:100px;background:#ccc;position:absolute;left:0px;top:110px;}
#div3{width:100px;height:100px;background:red;position:absolute;left:220px;top:0px;filter:alpha(opacity:30);opacity:0.3;}
#div4{width:100px;height:100px;background:red;position:absolute;left:330px;top:0px;filter:alpha(opacity:30);opacity:0.3;}
#div5{width:100px;height:100px;background:red;position:absolute;left:440px;top:0px;filter:alpha(opacity:30);opacity:0.3;}
</style>
<script type="text/javascript">
window.onload=function()
{
oDiv1=document.getElementById("div1");
oDiv2=document.getElementById("div2");
oDiv3=document.getElementById("div3");
oDiv4=document.getElementById("div4");
oDiv5=document.getElementById("div5");
oDiv1.onmouseover=function(){
Move(oDiv1,"width",200);
//alert(getStyle(oDiv1,"width"));
}
oDiv1.onmouseout=function(){
Move(oDiv1,"width",100);
}
oDiv2.onmouseover=function(){
Move(oDiv2,"height",200);
}
oDiv2.onmouseout=function(){
Move(oDiv2,"height",100);
}
oDiv3.onmouseover=function(){
Move(oDiv3,"opacity",100);
}
oDiv3.onmouseout=function(){
Move(oDiv3,"opacity",30);
}
oDiv4.onmouseover=function(){
Move(oDiv4,"opacity",100);
}
oDiv4.onmouseout=function(){
Move(oDiv4,"opacity",30);
}
oDiv5.onmouseover=function(){
Move(oDiv5,"opacity",100);
}
oDiv5.onmouseout=function(){
Move(oDiv5,"opacity",30);
}
}
//獲取行間樣式
function getStyle(obj,attr) //getStyle 非行間屬性 結(jié)果值為 ***px
{ if(obj.currentStyle)
{
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
//多物體不同運(yùn)動框架
function Move(obj,attr,itarget)
{
clearInterval(obj.timer);
obj.timer=setInterval(function(){
if(attr=="opacity")
{ cur=parseFloat(getStyle(obj,attr))*100;
speed=(itarget-cur)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(cur==itarget)
{
clearInterval(obj.timer);
}else
{ cur+=speed;
obj.style.opacity=cur/100;
obj.style.filter="alpha(opacity:"+cur+")";
}
}
else
{
cur=parseInt(getStyle(obj,attr));
speed=(itarget-cur)/10; //parseInt 獲取的值轉(zhuǎn)化為數(shù)
speed=speed>0?Math.ceil(speed):Math.floor(speed); //向下、向上取正
if(cur==itarget)
{
clearInterval(obj.timer);
}else
{
obj.style[attr]=cur+speed+"px";
}
}
},30)
}
</script>
</head>
<body>
<div id="div1">變寬</div>
<div id="div2">變高</div>
<div id="div3"></div>
<div id="div4"></div>
<div id="div5"></div>
</body>
</html>
相關(guān)文章
BootStrap table實(shí)現(xiàn)表格行拖拽效果
這篇文章主要為大家詳細(xì)介紹了BootStrap table實(shí)現(xiàn)表格行拖拽效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12
JavaScript 拖拽與觀察者模式的實(shí)現(xiàn)及應(yīng)用小結(jié)
本文通過代碼片段詳細(xì)介紹了JavaScript中的拖拽功能和觀察者模式(發(fā)布-訂閱模式)的實(shí)現(xiàn)及其應(yīng)用場景,拖拽功能允許用戶通過鼠標(biāo)移動元素,而觀察者模式則定義了一種一對多的依賴關(guān)系,使得對象能夠自動更新,感興趣的朋友跟隨小編一起看看吧2025-01-01
JS實(shí)現(xiàn)二維數(shù)組元素的排列組合運(yùn)算簡單示例
這篇文章主要介紹了JS實(shí)現(xiàn)二維數(shù)組元素的排列組合運(yùn)算,結(jié)合實(shí)例形式分析了javascript針對二維數(shù)組的遍歷、排列組合運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2019-01-01
JS?new操作原理及手寫函數(shù)模擬實(shí)現(xiàn)示例
這篇文章主要為大家介紹了JS?new操作原理及手寫函數(shù)模擬實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
基于jquery實(shí)現(xiàn)導(dǎo)航菜單高亮顯示(兩種方法)
本篇文章是基于jquery實(shí)現(xiàn)導(dǎo)航菜單高亮顯示,當(dāng)點(diǎn)擊不同導(dǎo)航菜單實(shí)現(xiàn)當(dāng)前點(diǎn)擊的菜單是高亮的,有需要的朋友可以關(guān)注下本文2015-08-08
ionic+html5+API實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用
這篇文章主要為大家詳細(xì)介紹了ionic+html5+API實(shí)現(xiàn)雙擊返回鍵退出應(yīng)用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-09-09
JavaScript實(shí)現(xiàn)經(jīng)緯度轉(zhuǎn)換成地址功能
這篇文章主要介紹了JavaScript實(shí)現(xiàn)經(jīng)緯度轉(zhuǎn)換成地址,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-03-03
微信小程序中不同頁面?zhèn)鬟f參數(shù)的操作方法
這篇文章主要介紹了微信小程序中不同頁面?zhèn)鬟f參數(shù)的操作方法,在開發(fā)項目中,避免不了不同頁面之間傳遞數(shù)據(jù)等,那么就需要進(jìn)行不同頁面之間的一個數(shù)據(jù)傳遞的,需要的朋友可以參考下2023-12-12

