需要帮助修改小javascript旋转图像

时间:2014-02-04 07:31:38

标签: javascript jquery rotation

我发现这个小代码用于在占位符中旋转图像,此时我只能放置一个,有人可以帮我编码,将不同的文件夹放在相同或不同的页面中旋转..

     <script language="JavaScript1.2">

var howOften = 5; //number often in seconds to rotate
var current = 0; //start the counter at 0
var ns6 = document.getElementById&&!document.all; //detect netscape 6

// place your images, text, etc in the array elements here
var items = new Array();
    items[0]="<a href='images/rotate/1.jpg'><img alt='image0 (9K)' src='images/rotate/1.jpg' height='300' width='300' border='0' /></a>"; //a linked image
    items[1]="<a href='images/rotate/2.jpg'><img alt='image1 (9K)' src='images/rotate/2.jpg' height='300' width='300' border='0' /></a>"; //a linked image
    items[2]="<a href='images/rotate/3.jpg'><img alt='image2 (9K)' src='images/rotate/3.jpg' height='300' width='300' border='0' /></a>"; //a linked image
    items[3]="<a href='images/rotate/4.jpg'><img alt='image3 (9K)' src='images/rotate/4.jpg' height='300' width='300' border='0' /></a>"; //a linked image
    items[4]="<a href='images/rotate/1.jpg'><img alt='image4 (9K)' src='images/rotate/1.jpg' height='300' width='300' border='0' /></a>"; //a linked image
    items[5]="<a href='images/rotate/2.jpg'><img alt='image5 (18K)' src='images/rotate/2.jpg' height='300' width='300' border='0' /></a>"; //a linked image
function rotater() {
    document.getElementById("placeholder").innerHTML = items[current];
    current = (current==items.length-1) ? 0 : current + 1;
    setTimeout("rotater()",howOften*1000);
}

function rotater() {
    if(document.layers) {
        document.placeholderlayer.document.write(items[current]);
        document.placeholderlayer.document.close();
    }
    if(ns6)document.getElementById("placeholderdiv").innerHTML=items[current]
        if(document.all)
            placeholderdiv.innerHTML=items[current];

    current = (current==items.length-1) ? 0 : current + 1; //increment or reset
    setTimeout("rotater()",howOften*1000);
}
window.onload=rotater;
//-->
</script>

1 个答案:

答案 0 :(得分:0)

尝试使用jquery插件,如jCarousel或rCarousel

http://sorgalla.com/jcarousel/