Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Conflitto tra js?

  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    68

    Conflitto tra js?

    Ciao!
    Ho una pagina html in cui ho inserito due javascript, tra l'altro presi proprio da questo sito.
    Il primo è un effetto di transizione di immagini, inserito nell'head tranne l'istruzione onLoad nel body e il riferimento alle immagini nelle varie celle della tabella.

    Il secondo è un esempio di testo scorrevole.

    Vi posto i codici:

    Transizione - head:
    <SCRIPT language="javascript1.2">

    var slideShowSpeed = 5000
    var slideShowSpeed1 = 4000
    var slideShowSpeed2 = 4000
    var slideShowSpeed3 = 5000

    var crossFadeDuration = 7

    var Pic = new Array()
    var Pic1 = new Array()
    var Pic2 = new Array()
    var Pic3 = new Array()

    Pic[0] = 'img/46.gif'
    Pic[1] = 'img/38.gif'
    Pic[2] = 'img/29.gif'
    Pic[3] = 'img/35.gif'
    Pic[4] = 'img/11.gif'

    Pic1[0] = 'img/19.gif'
    Pic1[1] = 'img/28.gif'
    Pic1[2] = 'img/36.gif'
    Pic1[3] = 'img/33.gif'
    Pic1[4] = 'img/23.gif'

    Pic2[0] = 'img/31.gif'
    Pic2[1] = 'img/40.gif'
    Pic2[2] = 'img/16.gif'
    Pic2[3] = 'img/43.gif'
    Pic2[4] = 'img/45.gif'

    Pic3[0] = 'img/22.gif'
    Pic3[1] = 'img/30.gif'
    Pic3[2] = 'img/26.gif'
    Pic3[3] = 'img/15.gif'
    Pic3[4] = 'img/18.gif'

    var t
    var j = 0
    var j1 = 0
    var j2 = 0
    var j3 = 0

    var p = Pic.length
    var p1 = Pic1.length
    var p2 = Pic2.length
    var p3 = Pic3.length

    var preLoad = new Array()
    var preLoad1 = new Array()
    var preLoad2 = new Array()
    var preLoad3 = new Array()

    for (i = 0; i < p; i++){
    preLoad[i] = new Image()
    preLoad[i].src = Pic[i]
    }
    for (i = 0; i < p1; i++){
    preLoad1[i] = new Image()
    preLoad1[i].src = Pic1[i]
    }
    for (i = 0; i < p2; i++){
    preLoad2[i] = new Image()
    preLoad2[i].src = Pic2[i]
    }
    for (i = 0; i < p3; i++){
    preLoad3[i] = new Image()
    preLoad3[i].src = Pic3[i]
    }

    function runSlideShow(){
    if (document.all){
    document.images.SlideShow.style.filter="blendTrans (duration=2)"
    document.images.SlideShow.style.filter="blendTrans (duration=crossFadeDuration)"
    document.images.SlideShow.filters.blendTrans.Apply ()
    }
    document.images.SlideShow.src = preLoad[j].src
    if (document.all){
    document.images.SlideShow.filters.blendTrans.Play( )
    }
    j = j + 1
    if (j > (p-1)) j=0
    t = setTimeout('runSlideShow()', slideShowSpeed)
    }

    function runSlideShow1(){
    if (document.all){
    document.images.SlideShow1.style.filter="blendTran s(duration=2)"
    document.images.SlideShow1.style.filter="blendTran s(duration=crossFadeDuration)"
    document.images.SlideShow1.filters.blendTrans.Appl y()
    }
    document.images.SlideShow1.src = preLoad1[j1].src
    if (document.all){
    document.images.SlideShow1.filters.blendTrans.Play ()
    }
    j1 = j1 + 1
    if (j1 > (p1-1)) j1=0
    t = setTimeout('runSlideShow1()', slideShowSpeed1)
    }

    function runSlideShow2(){
    if (document.all){
    document.images.SlideShow2.style.filter="blendTran s(duration=2)"
    document.images.SlideShow2.style.filter="blendTran s(duration=crossFadeDuration)"
    document.images.SlideShow2.filters.blendTrans.Appl y()
    }
    document.images.SlideShow2.src = preLoad2[j2].src
    if (document.all){
    document.images.SlideShow2.filters.blendTrans.Play ()
    }
    j2 = j2 + 1
    if (j2 > (p2-1)) j2=0
    t = setTimeout('runSlideShow2()', slideShowSpeed2)
    }
    function runSlideShow3(){
    if (document.all){
    document.images.SlideShow3.style.filter="blendTran s(duration=2)"
    document.images.SlideShow3.style.filter="blendTran s(duration=crossFadeDuration)"
    document.images.SlideShow3.filters.blendTrans.Appl y()
    }
    document.images.SlideShow3.src = preLoad3[j3].src
    if (document.all){
    document.images.SlideShow3.filters.blendTrans.Play ()
    }
    j3 = j3 + 1
    if (j3 > (p3-1)) j3=0
    t = setTimeout('runSlideShow3()', slideShowSpeed3)
    }

    </SCRIPT>


    Testo scorrevole: body:

    <script language="JavaScript1.2">

    var marqueewidth=300

    var marqueeheight=20

    var marqueespeed=2

    var marqueebgcolor="#DFE9EC"

    var pauseit=1


    var marqueecontent='<nobr><font face="Verdana" color="#FF0000">[b]Per ricevere informazioni sulle offerte promozionali, iscriviti alla nostra Newsletter. Clicca qui!!!!</font></nobr>'

    var copyspeed=marqueespeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var iedom=document.all||document.getElementById
    if (iedom)
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100;left:-1000">'+marqueecontent+'</span>')
    var actualwidth=''
    var cross_marquee, ns_marquee

    function populate(){
    if (iedom){
    cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
    cross_marquee.style.left=marqueewidth+8
    cross_marquee.innerHTML=marqueecontent
    actualwidth=document.all? cross_marquee.offsetWidth : document.getElementById("temp").offsetWidth
    }
    else if (document.layers){
    ns_marquee=document.ns_marquee.document.ns_marquee 2
    ns_marquee.left=marqueewidth+8
    ns_marquee.document.write(marqueecontent)
    ns_marquee.document.close()
    actualwidth=ns_marquee.document.width
    }
    lefttime=setInterval("scrollmarquee()",20)
    }
    window.onload=populate

    function scrollmarquee(){
    if (iedom){
    if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
    cross_marquee.style.left=parseInt(cross_marquee.st yle.left)-copyspeed
    else
    cross_marquee.style.left=marqueewidth+8

    }
    else if (document.layers){
    if (ns_marquee.left>(actualwidth*(-1)+8))
    ns_marquee.left-=copyspeed
    else
    ns_marquee.left=marqueewidth+8
    }
    }

    if (iedom||document.layers){
    with (document){
    document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
    if (iedom){
    write('<div style="position:relative;width:'+marqueewidth+';he ight:'+marqueeheight+';overflow:hidden">')
    write('<div style="position:absolute;width:'+marqueewidth+';he ight:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
    write('<div id="iemarquee" style="position:absolute;left:0;top:0"></div>')
    write('</div>')
    }
    else if (document.layers){
    write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
    write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
    write('</ilayer>')
    }
    document.write('</td></table>')
    }
    }
    </script>


    Il problema sta' nel fatto che se inserisco entrambi nella pagina html, funziona solo il testo scorrevole. Se non inserisco il js relativo a quest'ultimo, il primo invece funziona. Dov'è l'errore? O è una questione di conflitto tra i due js?

    Scusate il msg kilometrico....

    Grazie grazie!
    Fla

  2. #2
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Ci puo' essere un solo gestore dell'evento onload... elimina la riga

    window.onload=populate

    ed aggiungi il richiamo nel tag body:

    <body onload="runSlideShow();populate();">

    ciao
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2002
    Messaggi
    68
    Ok grazie ora provo.

    visto che siete stati così gentili posso abusare della vostra bontà?

    Come si può fare ad 'attaccare' un link a questo js?
    o meglio, per esempio, all'ultima frase che viene visualizzata

    Questo è l'url dell'esempio
    http://www.html.it/mailing/archivio/79/index.html

    Questo è il codice:

    <script language="JavaScript1.2">
    <!--

    var line=new Array()
    line[1]="HTML.it"
    line[2]="il sito italiano sul Web publishing"
    line[3]="400 applet Java"
    line[4]="300 Javascript e molto altro"
    line[5]="www.html.it" (qui vorrei poter linkare ad un'altra pagina )

    var ts_fontsize="16px"

    var longestmessage=1
    for (i=2;i<line.length;i++){
    if (line[i].length>line[longestmessage].length)
    longestmessage=i
    }

    var tscroller_width=line[longestmessage].length

    lines=line.length-1

    if (document.all||document.getElementById){
    document.write('<form name="bannerform">')
    document.write('<input type="text" name="banner" size="'+tscroller_width+'"')
    document.write(' style="background-color: '+document.bgColor+'; color: '+document.body.text+'; font-family: verdana; font-size: '+ts_fontsize+'; font-weight:bold; border: medium none" onfocus="blur()">')
    document.write('</form>')
    }

    temp=""
    nextchar=-1;
    nextline=1;
    cursor="\\"
    function animate(){
    if (temp==line[nextline] & temp.length==line[nextline].length & nextline!=lines){
    nextline++;
    nextchar=-1;
    document.bannerform.banner.value=temp;
    temp="";
    setTimeout("nextstep()",1000)}
    else if (nextline==lines & temp==line[nextline] & temp.length==line[nextline].length){
    nextline=1;
    nextchar=-1;
    document.bannerform.banner.value=temp;
    temp="";
    setTimeout("nextstep()",1000)}
    else{
    nextstep()}}

    function nextstep(){

    if (cursor=="\\"){
    cursor="|"}
    else if (cursor=="|"){
    cursor="/"}
    else if (cursor=="/"){
    cursor="-"}
    else if (cursor=="-"){
    cursor="\\"}


    nextchar++;
    temp+=line[nextline].charAt(nextchar);
    document.bannerform.banner.value=temp+cursor
    setTimeout("animate()",25)}

    if (document.all||document.getElementById)
    window.onload=animate
    // -->
    </script>


    Spero che poi non generi problemi a parte anche qui l'onload che gestirò come mi avete detto di fare per l'altro esempio.

    Grazie grazie grazie.
    Fla

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.