js左右轮转切换特效
<div id="changeOptions">
<a>
    <span style="cursor:pointer"  onclick="left();"><<</span>
    </a>
    
    <a href="#"></a>
    <span id="first" onclick="chooseMode('first')">容易</span>
    
    <a href="#"></a>
    <span id="second" onclick="chooseMode('second')">一般</span>
    
    
    <a>
    <span style="cursor:pointer" onclick="right();">>></span>
    </a>

</div>



<script>
     var arrayList = new Array();
var index ;
var left_index;
var arrLength ;

function chooseMode(v){
if ('first'==v) {
alert(document.getElementById('first').innerHTML);
document.getElementById('mode').value= getMode(document.getElementById('first').innerHTML);
} else if('second'==v){
alert(document.getElementById('second').innerHTML);
document.getElementById('mode').value= getMode(document.getElementById('second').innerHTML);
}
}



function initModes()
{
index = 0;
left_index = index;

arrayList[0]= [1,'容易'];

arrayList[1]= [2,'一般'];

arrayList[2]= [3,'困难'];

arrayList[3]= [4,'特难'];

arrLength= arrayList.length;
document.getElementById("first").innerHTML = arrayList[0][1];
document.getElementById("second").innerHTML = arrayList[1][1];
//alert(document.getElementById("first").innerHTML);
}

function getMode(modeName){ //alert(modeName);
for (var i=0;i<arrLength; i++) {
if (modeName == arrayList[1]){
//alert(arrayList[0]+'-'+arrayList[1]);
return arrayList[0];
}
}
}

function right()
{
if(left_index<0){
index = arrLength + left_index;
left_index = 0;
}

index = index + 1;
if(index>(arrLength-1)){
index = 0;
}

if(index == arrLength-1)
{
document.getElementById("first").innerHTML = arrayList[index][1];
document.getElementById("second").innerHTML = arrayList[0][1];
}
else{
document.getElementById("first").innerHTML = arrayList[index][1];
document.getElementById("second").innerHTML = arrayList[index+1][1];
}
//alert('index='+index+'|left_index='+left_index);
}

function left()
{
    
    if (index > 0){
     left_index = index-arrLength;
     index = 0;
    }
    
    left_index = left_index - 1;
    if (left_index<=(-arrLength)) {
     left_index = 0;
     document.getElementById("first").innerHTML = arrayList[0][1];
document.getElementById("second").innerHTML = arrayList[1][1];
    } else {
     document.getElementById("first").innerHTML = arrayList[arrLength+left_index][1];
document.getElementById("second").innerHTML = arrayList[(arrLength+left_index)==(arrLength-1)?0:(arrLength+left_index+1)][1];
    }
    //alert('left='+left_index+'|index='+index);


}

initModes();
    </script>



lunzi   2010-11-17 22:25:52 评论:1   阅读:2535   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog