JS焦點(diǎn)圖切換,上下翻轉(zhuǎn)
更新時(shí)間:2011年05月12日 01:13:08 作者:
JS焦點(diǎn)圖切換,上下翻轉(zhuǎn),不妥的地方望指正
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mypaly</title>
<style type="text/css">
* { margin:0; padding:0;}
ul, li { list-style:none;}
body{
text-align:center;
}
#play{
width:400px;
height:300px;
position:absolute;
left:50%;
top:50%;
margin:-155px 0 0 -205px;
overflow:hidden;
}
#playimg{
width:400px;
height:300px;
position:absolute;
}
#playimg li{
height:300px;
overflow:hidden;
}
#playimg img{
width:400px;
height:300px;
}
#playbtn{
position:absolute;
left:0;
bottom:5px;
}
#playbtn li{
display:inline;
background:#eee;
padding:2px 5px;
margin:0 3px;
cursor:pointer;
}
#playbtn .current{
background:#f0f;
}
</style>
<script type="text/javascript">
function $(id){return document.getElementById(id)}
function moveElement(elementID,final_x,final_y,interval) {//這個(gè)方法在DOM藝術(shù)那個(gè)書上講的很清楚
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
function imgChange(num){//切換圖片焦點(diǎn)
if(!$('play')) return false;
var piclist=$('playimg').getElementsByTagName('img');
var imgheight=piclist[0].offsetHeight;
var moveY=-(imgheight*num);
moveElement('playimg',0,moveY,5);
}
function classToggle(arr,n){//切換按鈕樣式
for(var i=0;i<arr.length;i++){
arr[i].className='';
}
arr[n].className='current';
}
function btnChange(btns){//鼠標(biāo)移動(dòng)播放
if(!$(btns)) return false;
$('play').onmouseover = function(){autokey = false};
$('play').onmouseout = function(){autokey = true};
var arr=$(btns).getElementsByTagName('li');
for(var i=0;i<arr.length;i++){
arr[i].index=i;//設(shè)置索引號(hào)
arr[i].onmouseover=function(){
//var num=index(this,arr);
classToggle(arr,this.index);
imgChange(this.index);
}
}
}
function autoChange(btns){
if(!$(btns)) return false;
if(!autokey) return false;
var arr=$(btns).getElementsByTagName('li');
for(var i=0;i<arr.length;i++){
if(arr[i].className=='current'){
var n=i+1;
}
}
if(n>=arr.length) n=0;
classToggle(arr,n);
imgChange(n);
}
var autokey = true;
setInterval("autoChange('playbtn')",3000);
window.onload=function(){
btnChange('playbtn');
}
</script>
</head>
<body>
<div id="play">
<ul id="playimg">
<li><img src="../images/Blue hills.jpg" alt="" /></li>
<li><img src="../images/Sunset.jpg" alt="" /></li>
<li><img src="../images/Water lilies.jpg" alt="" /></li>
<li><img src="../images/Winter.jpg" alt="" /></li>
</ul>
<ul id="playbtn"><li class="current">1</li><li>2</li><li>3</li><li>4</li></ul>
</div>
</body>
</html>
您可能感興趣的文章:
- Android實(shí)現(xiàn)文字翻轉(zhuǎn)動(dòng)畫的效果
- Android利用Camera實(shí)現(xiàn)中軸3D卡牌翻轉(zhuǎn)效果
- Android實(shí)現(xiàn)圖片反轉(zhuǎn)、翻轉(zhuǎn)、旋轉(zhuǎn)、放大和縮小
- Android實(shí)現(xiàn)Flip翻轉(zhuǎn)動(dòng)畫效果
- Android動(dòng)畫之3D翻轉(zhuǎn)效果實(shí)現(xiàn)函數(shù)分析
- Android圖片翻轉(zhuǎn)動(dòng)畫簡(jiǎn)易實(shí)現(xiàn)代碼
- JQuery學(xué)習(xí)筆記 實(shí)現(xiàn)圖片翻轉(zhuǎn)效果和TAB標(biāo)簽切換效果
- 如何使用Matrix對(duì)bitmap的旋轉(zhuǎn)與鏡像水平垂直翻轉(zhuǎn)
- PHP圖片處理之圖片旋轉(zhuǎn)和圖片翻轉(zhuǎn)實(shí)例
- Android實(shí)現(xiàn)卡片翻轉(zhuǎn)動(dòng)畫
相關(guān)文章
求解開jscript.encode代碼的asp函數(shù)
求解開jscript.encode代碼的asp函數(shù)...2007-02-02全選并改變TR顏色的javascript實(shí)現(xiàn)代碼
網(wǎng)頁(yè)特效 全選并改變TR顏色2010-03-03mouseover時(shí)顯示滾動(dòng)字幕 特效
mouseover時(shí)顯示滾動(dòng)字幕 特效...2007-02-02