Pregunta

He estado buscando en la red difícil para algunos código javascript que me permite desplazarse automáticamente imágenes no dejan de forma horizontal en una página web. Después de un minucioso desde hace mucho tiempo, finalmente me encontré con algo que era lo suficientemente cerca. entonces yo lo había modificado tanto como sea posible para que haga exactamente lo que quería que hiciera.

Esta prueba fue hecha en una página sin un DOCTYPE, así que cuando lo moví a una página que tenía un DOCTYPE, el javascript quedó en mal estado y se negó a desplazarse. Sólo mostró una sola imagen fija (en Safari y Firefox)

He subido dos páginas de mi sitio MobileMe por lo que ustedes pueden echar un vistazo.

La página sin un DOCTYPE: web.me.com/zubby

La página con un DOCTYPE: web.me.com/zubby/2.html

el javascript también se detalla a continuación. Yo estaré muy agradecido si alguien me puede ayudar con esto.

Sólo subido los archivos pertinentes a fin de Firebug es probable que se quejan de las funciones inexistentes.

var pic = new Array();

function banner(name, width, link){
    this.name = name
    this.width = width
    this.link = link
   };

pic[0] = new banner('images/cellarpics/cellarbynightsmall.jpg',203,'images/cellarpics/cellarbynightsmall.jpg');
pic[1] = new banner('images/cellarpics/insidecellarnewsmall.jpg',203,'images/cellarpics/insidecellarnewsmall.jpg');
pic[2] = new banner('images/cellarpics/mainshotwebsmall.jpg',203,'images/cellarpics/mainshotwebsmall.jpg');
pic[3] = new banner('images/cellarpics/MicroCelllar2tileopensmall.jpg',203,'images/cellarpics/MicroCelllar2tileopensmall.jpg');
pic[4] = new banner('images/cellarpics/openmicrosmall.jpg',203,'images/cellarpics/openmicrosmall.jpg');
pic[5] = new banner('images/cellarpics/topopenweb1small.jpg',203,'images/cellarpics/topopenweb1small.jpg');
pic[6] = new banner('images/cellarpics/topweb2small.jpg',203,'images/cellarpics/topweb2small.jpg');
pic[7] = new banner('images/cellarpics/topwebclosed1small.jpg',203,'images/cellarpics/topwebclosed1small.jpg');
/*
pic[8] = new banner('http://www.sxc.hu/pic/s/d/da/da9l/290444_yellow_rose.jpg',102,'http://www.sxc.hu/pic/m/d/da/da9l/290444_yellow_rose.jpg')
*/

var speed = 10;

var kk = pic.length;
var ii;
var hhh;
var nnn;
var myInterval;
var myPause;
var mode = 0;


var imgArray = new Array(kk);
var myLeft = new Array(kk);

for (ii=0;ii<kk;ii++){
imgArray[ii] = new Image()
imgArray[ii].src = pic[ii].name
imgArray[ii].width = pic[ii].width

    hhh=0 
    for (nnn=0;nnn<ii;nnn++){
        hhh=hhh+pic[nnn].width
    };
    myLeft[ii] = hhh
};

function ready(){
    for (ii=0;ii<kk;ii++){ 
        if (document.images[ii].complete == false){
            return false    
            break
        };
    };
return true
};


function startScrolling(){
    if (ready() == true){       
        window.clearInterval(myPause)
        myInterval = setInterval("autoScroll()",speed)  
    };
};


function autoScroll(){
    for (ii=0;ii<kk;ii++){
        myLeft[ii] = myLeft[ii] - 1

    if (myLeft[ii] == -(pic[ii].width)){
        hhh = 0
        for (nnn=0;nnn<kk;nnn++){
            if (nnn!=ii){
                hhh = hhh + pic[nnn].width
            };      
        };
        myLeft[ii] =  hhh
    };


        document.images[ii].style.left = myLeft[ii]
    };
    mode = 1
};

function stop(){
    if (mode == 1){
        window.clearInterval(myInterval)
    };
    if (mode == 0){
        window.clearInterval(myPause)
    };  
};

function go(){
    if (mode == 1){
        myInterval = setInterval("autoScroll()",speed)
    };
    if (mode == 0){
        myPause = setInterval("startScrolling()",3000)
    };  
};

myPause = setInterval("startScrolling()",100)

for (ii=0;ii<kk;ii++){
document.write('<a href="' + pic[ii].link + '" target="_blank"><img style="height:131px;position:absolute;top:0;left:' + myLeft[ii]  + ';" src="' + pic[ii].name + '" onMouseOver="stop()" onMouseOut="go()" /></a>');
};
¿Fue útil?

Solución

En IE funciona. La razón es que con tipo de documento, el establecimiento de la declaración CSS dejó funciona de forma diferente, parece que sólo un número no es suficiente ... para hacer que funcione, en esta función de desplazamiento automático ()

Cambiar

document.images[ii].style.left = myLeft[ii]

a

document.images[ii].style.left = myLeft[ii] + "px"

Además, dos de las secuencias de comandos no se cargan, menu.js y JS / prettyPhoto.js

Otros consejos

La razón probable es que usted no tiene comillas alrededor de los atributos en la última línea de su código:

document.write('<a href = ' + pic[ii].link + 'target="_blank" ><img space=0 hspace=0 vspace=0 border=0 height=131 style=position:absolute;top:0;left:0' + myLeft[ii]  + '; src=' + pic[ii].name + ' onMouseOver=stop() onMouseOut=go()></a>')

document.write('<a href="' + pic[ii].link + '" target="_blank"><img style="height:131px;position:absolute;top:0;left:' + myLeft[ii]  + ';" src="' + pic[ii].name + '" onMouseOver="stop()" onMouseOut="go()" /></a>');

Además, te aconsejo fuertemente para agregar a su punto y coma Javascript.

Por último, utilizar una biblioteca para hacer todo esto y dormir más.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top