(43)JS運動之鏈式運動架構,js鏈式

來源:互聯網
上載者:User

(43)JS運動之鏈式運動架構,js鏈式

鏈式運動架構就是一系列的運動分階段進行,在普通的運動架構上加上一個參數function,這個function表示下一個要執行的動作,具體代碼如下:

<!DOCTYPE HTML><!--鏈式運動架構:運動分階段進行,當運動停止的時候,執行下一個運動--><html><head><meta charset="utf-8"><title></title><style>#div1 {width:100px;height:100px;background:red;filter:alpha(opacity:30);opacity:0.3}</style> <script>window.onload=function (){var oDiv=document.getElementById('div1');//先擷取div元素oDiv.onmouseover=function (){startMove(oDiv,'width',300,function(){//先是寬變300startMove(oDiv,'height',300,function(){//當寬變300的時候,即運動結束時候開啟另一個運動,使其高變為300startMove(oDiv,'opacity',100);//使透明度變成100,原來是30});});};oDiv.onmouseout=function ()//當滑鼠移出的時候,跟移進的時候效果相反即可。{startMove(oDiv,'opacity',30,function(){startMove(oDiv,'height',100,function(){startMove(oDiv,'width',100);});});};};//以下是運動架構的內容function getStyle(obj, name){if(obj.currentStyle){return obj.currentStyle[name];}else{return getComputedStyle(obj, false)[name];}}function startMove(obj, attr, iTarget, fnEnd)//比普通的運動架構寫多了一個函數,說明下一階段要執行的運動{clearInterval(obj.timer);obj.timer=setInterval(function (){var cur=0;if(attr=='opacity'){cur=Math.round(parseFloat(getStyle(obj, attr))*100);}else{cur=parseInt(getStyle(obj, attr));}var speed=(iTarget-cur)/6;speed=speed>0?Math.ceil(speed):Math.floor(speed);if(cur==iTarget){clearInterval(obj.timer);if(fnEnd)fnEnd();}else{if(attr=='opacity'){obj.style.filter='alpha(opacity:'+(cur+speed)+')';obj.style.opacity=(cur+speed)/100;}else{obj.style[attr]=cur+speed+'px';}}}, 30);}</script></head><body><div id="div1"></div></body></html>
:

當滑鼠移進的時候,先橫向變寬,再縱向變高,最後透明度變成100,效果如下:




當滑鼠移出的時候,效果剛好和上面相反:










怎在網頁架構中JS動態開啟超連結

根據你的說法好像不用後台來決定跳轉到哪個頁面!? 就是說可能在頁面就能完成去向。

如果你那個 1.html,2.html,3.html……,不多的話,可以用我寫的這個js跳轉。

主要代碼都在上架構的頁面上的,所以我只貼上架構的頁面代碼。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/...ct.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script>
//存放你下架構頁面的地址的列表
var webList = ["1.html", "2.html", "3.html"];

//用於鎖定當前頁面
var local = 0;
function goto(o, d){
if(d == "up"){
if(local -1 >= 0) {
o.href = webList[--local];
o.submit();
}else return;
}else{
if(local +1 < webList.length) {
o.href = webList[++local];
o.submit();
}else return;
}
o.href = "javascript:void(0)"
}
</script>
</head>

<body>
<p><a target="frame1" href="javascript:void(0)" onclick="goto(this, 'up')">上一頁</a>,
<a target="frame1" href="javascript:void(0)" onclick="goto(this, 'down')">下一頁</a></p>
</body>
</html>
>...餘下全文>>
 
對於JS控制架構中各視窗連結的問題

onclick="window.parent.frames[2].location.href=' www.baidu.com'"如你所說的,像top.html\left.html\right.html三個頁面都是屬於1.html的子頁面,在DOM中,它們都被包含在frames對象中,因此window.parent.frames[2]中,window屬於整個視窗聽對象,接下是parent也是三個子頁的父頁,再接下就是子頁,子頁由於是一個集合,因些在取值時可以用數字做為索引,0表示top。1表示left,2表示right。當然你也可以用它們的name值或者ID做為索引
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.