Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Javascript: su ie sì, su firefox e chrome no

    Ciao, sono al mio primo post, nonchè al mio primo javascript e non poteva mancare qualche piccolo problemino.
    Il javascript che allego di seguito, funziona correttamente su internet explorer 6, 7 e 8, ma non su firefox 2, 3 e su google chrome.
    Sul perchè non funzioni in chrome, non ho indizi.
    Ne ho invece su firefox: la console degli errori mi indica chiaramente che in ben definito punto del codice vi è un "event not defined".
    Leggendo qua e là mi sembra di aver capito che se trovo il modo di definire correttamente quel dato evento, allora lo script funzionerà anche in firefox.
    Purtroppo non ho idea di come fare.
    Qualcuno può cortesemente aiutarmi?
    Grazie!!

    Codice del javascript incriminato:

    <SCRIPT language=JavaScript>
    dCol='#008080';
    fCol='#00FFFF';
    sCol='#FF0000';
    mCol='#FF0000';
    hCol='#FF0000';
    ClockHeight=35;
    ClockWidth=35;
    ClockFromMouseY=0;
    ClockFromMouseX=100;

    d=new Array("DOMENICA","LUNEDí","MARTEDí","MERCOLEDí","G IOVEDí","VENERDí","SABATO");
    m=new Array("GENNAIO","FEBBRAIO","MARZO","APRILE","MAGGI O","GIUGNO","LUGLIO","AGOSTO","SETTEMBRE","OTTOBRE ","NOVEMBRE","DICEMBRE");
    date=new Date();
    day=date.getDate();
    year=date.getYear();
    if (year < 2000) year=year+1900;
    TodaysDate=" "+d[date.getDay()]+" "+day+" "+m[date.getMonth()]+" "+year;
    D=TodaysDate.split('');
    H='...';
    H=H.split('');
    M='....';
    M=M.split('');
    S='.....';
    S=S.split('');
    Face='1 2 3 4 5 6 7 8 9 10 11 12';
    font='arial';
    size=1;
    speed=0.6;
    ns=(document.layers);
    ie=(document.all);
    Face=Face.split(' ');
    n=Face.length;
    a=size*10;
    ymouse=0;
    xmouse=0;
    scrll=0;
    props="<font face="+font+" size="+size+" color="+fCol+">";
    props2="<font face="+font+" size="+size+" color="+dCol+">";
    Split=360/n;
    Dsplit=360/D.length;
    HandHeight=ClockHeight/4.5
    HandWidth=ClockWidth/4.5
    HandY=-7;
    HandX=-2.5;
    scrll=0;
    step=0.06;
    currStep=0;
    y=new Array();x=new Array();Y=new Array();X=new Array();
    for (i=0; i < n; i++){y[i]=0;x[i]=0;Y[i]=0;X[i]=0}
    Dy=new Array();Dx=new Array();DY=new Array();DX=new Array();
    for (i=0; i < D.length; i++){Dy[i]=0;Dx[i]=0;DY[i]=0;DX[i]=0}
    if (ns){
    for (i=0; i < D.length; i++)
    document.write('<layer name="nsDate'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props2+D[i]+'</font></center></layer>');
    for (i=0; i < n; i++)
    document.write('<layer name="nsFace'+i+'" top=0 left=0 height='+a+' width='+a+'><center>'+props+Face[i]+'</font></center></layer>');
    for (i=0; i < S.length; i++)
    document.write('<layer name=nsSeconds'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+sCol+'><center>'+S[i]+'</center></font></layer>');
    for (i=0; i < M.length; i++)
    document.write('<layer name=nsMinutes'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+mCol+'><center>'+M[i]+'</center></font></layer>');
    for (i=0; i < H.length; i++)
    document.write('<layer name=nsHours'+i+' top=0 left=0 width=15 height=15><font face=Arial size=3 color='+hCol+'><center>'+H[i]+'</center></font></layer>');
    }
    if (ie){
    document.write('<div id="Od" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < D.length; i++)
    document.write('<div id="ieDate" style="position:absolute;top:0px;left:0;height:'+a +';width:'+a+';text-align:center">'+props2+D[i]+'
    </font></div>');
    document.write('</div></div>');
    document.write('<div id="Of" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < n; i++)
    document.write('<div id="ieFace" style="position:absolute;top:0px;left:0;height:'+a +';width:'+a+';text-align:center">'+props+Face[i]+'
    </font></div>');
    document.write('</div></div>');
    document.write('<div id="Oh" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < H.length; i++)
    document.write('<div id="ieHours" style="position:absolute;width:16px;height:16px;fo nt-family:Arial;font-size:16px;color:'+hCol+';text-align:center;font-weight:bold">'+H[i]+'</div>');
    document.write('</div></div>');
    document.write('<div id="Om" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < M.length; i++)
    document.write('<div id="ieMinutes" style="position:absolute;width:16px;height:16px;fo nt-family:Arial;font-size:16px;color:'+mCol+';text-align:center;font-weight:bold">'+M[i]+'</div>');
    document.write('</div></div>')
    document.write('<div id="Os" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
    for (i=0; i < S.length; i++)
    document.write('<div id="ieSeconds" style="position:absolute;width:16px;height:16px;fo nt-family:Arial;font-size:16px;color:'+sCol+';text-align:center;font-weight:bold">'+S[i]+'</div>');
    document.write('</div></div>')
    }
    (ns)?window.captureEvents(Event.MOUSEMOVE):0;
    function Mouse(evnt){
    ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
    xmouse = (ns)?evnt.pageX+ClockFromMouseX:event.x+ClockFromM ouseX;
    }
    (ns)?window.onMouseMove=Mouse:document.onmousemove =Mouse;
    function ClockAndAssign(){
    time = new Date ();
    secs = time.getSeconds();
    sec = -1.57 + Math.PI * secs/30;
    mins = time.getMinutes();
    min = -1.57 + Math.PI * mins/30;
    hr = time.getHours();
    hrs = -1.575 + Math.PI * hr/6+Math.PI*parseInt(time.getMinutes())/360;
    if (ie){
    Od.style.top=window.document.body.scrollTop;
    Of.style.top=window.document.body.scrollTop;
    Oh.style.top=window.document.body.scrollTop;
    Om.style.top=window.document.body.scrollTop;
    Os.style.top=window.document.body.scrollTop;
    }
    for (i=0; i < n; i++){
    var F=(ns)?document.layers['nsFace'+i]:ieFace[i].style;
    F.top=y[i] + ClockHeight*Math.sin(-1.0471 + i*Split*Math.PI/180)+scrll;
    F.left=x[i] + ClockWidth*Math.cos(-1.0471 + i*Split*Math.PI/180);
    }
    for (i=0; i < H.length; i++){
    var HL=(ns)?document.layers['nsHours'+i]:ieHours[i].style;
    HL.top=y[i]+HandY+(i*HandHeight)*Math.sin(hrs)+scrll;
    HL.left=x[i]+HandX+(i*HandWidth)*Math.cos(hrs);
    }
    for (i=0; i < M.length; i++){
    var ML=(ns)?document.layers['nsMinutes'+i]:ieMinutes[i].style;
    ML.top=y[i]+HandY+(i*HandHeight)*Math.sin(min)+scrll;
    ML.left=x[i]+HandX+(i*HandWidth)*Math.cos(min);
    }
    for (i=0; i < S.length; i++){
    var SL=(ns)?document.layers['nsSeconds'+i]:ieSeconds[i].style;
    SL.top=y[i]+HandY+(i*HandHeight)*Math.sin(sec)+scrll;
    SL.left=x[i]+HandX+(i*HandWidth)*Math.cos(sec);
    }
    for (i=0; i < D.length; i++){
    var DL=(ns)?document.layers['nsDate'+i]:ieDate[i].style;
    DL.top=Dy[i] + ClockHeight*1.5*Math.sin(currStep+i*Dsplit*Math.PI/180)+scrll;
    DL.left=Dx[i] + ClockWidth*1.5*Math.cos(currStep+i*Dsplit*Math.PI/180);
    }
    currStep-=step;
    }
    function Delay(){
    scrll=(ns)?window.pageYOffset:0;
    Dy[0]=Math.round(DY[0]+=((ymouse)-DY[0])*speed);
    Dx[0]=Math.round(DX[0]+=((xmouse)-DX[0])*speed);
    for (i=1; i < D.length; i++){
    Dy[i]=Math.round(DY[i]+=(Dy[i-1]-DY[i])*speed);
    Dx[i]=Math.round(DX[i]+=(Dx[i-1]-DX[i])*speed);
    }
    y[0]=Math.round(Y[0]+=((ymouse)-Y[0])*speed);
    x[0]=Math.round(X[0]+=((xmouse)-X[0])*speed);
    for (i=1; i < n; i++){
    y[i]=Math.round(Y[i]+=(y[i-1]-Y[i])*speed);
    x[i]=Math.round(X[i]+=(x[i-1]-X[i])*speed);
    }
    ClockAndAssign();
    setTimeout('Delay()',20);
    }
    if (ns||ie)window.onload=Delay;
    </SCRIPT>



    Firefox indica che la riga che da problemi è questa:

    ymouse = (ns)?evnt.pageY+ClockFromMouseY-(window.pageYOffset):event.y+ClockFromMouseY;
    Consulente informatico, web designer karateca e fotografo.
    www.ferlinghetti.net
    www.karatebrescia.it

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2000
    Messaggi
    938
    Ciao,

    quello script non è compatibile con Firefox ma solo con Netscape 4.5 document.layers

    prova questo, l'autore è lo stesso

    Codice PHP:
    <html>
    <
    head>
    <
    style type="text/css">
    <!--
    /*Do not Alter these. Set for alignment*/
    .css1{
    position:absolute;top:0px;left:0px;
    width:16px;height:16px;
    font-family:Arial;
    font-size:16px;
    text-align:center;
    font-weight:bold;
    }
    .
    css2{
    position:absolute;top:0px;left:0px;
    width:10px;height:10px;
    font-family:Arial;
    font-size:10px;
    text-align:center;
    }
    //-->
    </style>
    </
    head>
    <
    body>
    <
    SCRIPT LANGUAGE="JavaScript">


    //Hide from older browsers 
    if (document.getElementById&&!document.layers){

    //Clock colours
    dCol='000080';//date colour. 
    fCol='000000';//face colour. 
    sCol='FF0000';//seconds colour. 
    mCol='0000FF';//minutes colour. 
    hCol='000000';//hours colour.


    //Controls
    del=0.6;  //Follow mouse speed.
    ref=10;   //Run speed (timeout).

    //Alter nothing below! Alignments will be lost!
    var ieType=(typeof window.innerWidth != 'number');
    var 
    docComp=(document.compatMode);
    var 
    docMod=(docComp && docComp.indexOf("CSS") != -1);
    var 
    ieRef=(ieType && docMod)?document.documentElement:document.body;
    theDays=new Array("DOMENICA","LUNEDÌ","MARTEDÌ","MERCOLEDÌ","GIOVEDÌ","VENERDÌ","SABATO"); 
    theMonths=new Array("GENNAIO","FEBBRAIO","MARZO","APRILE","MAGGIO","GIUGNO","LUGLIO","AGOSTO","SETTEMBRE","OTTOBRE","NOVEMBRE","DICEMBRE");
    date=new Date();
    day=date.getDate();
    year=date.getYear();
    if (
    year 2000year=year+1900
    tmpdate=" "+theDays[date.getDay()]+" "+day+" "+theMonths[date.getMonth()]+" "+year;
    D=tmpdate.split("");
    N='3 4 5 6 7 8 9 10 11 12 1 2';
    N=N.split(" ");
    F=N.length;
    H='...';
    H=H.split("");
    M='....';
    M=M.split("");
    S='.....';
    S=S.split("");
    siz=40;
    eqf=360/F;
    eqd=360/D.length;
    han=siz/5.5;
    ofy=-7;
    ofx=-3;
    ofst=70;
    tmr=null;
    vis=true;
    mouseY=0;
    mouseX=0;
    dy=new Array();
    dx=new Array();
    zy=new Array();
    zx=new Array();
    tmps=new Array();
    tmpm=new Array(); 
    tmph=new Array();
    tmpf=new Array(); 
    tmpd=new Array();
    var 
    sum=parseInt(D.length+F+H.length+M.length+S.length)+1;
    for (
    i=0sumi++){
    dy[i]=0;
    dx[i]=0;
    zy[i]=0;
    zx[i]=0;
    }

    algn=new Array();
    for (
    i=0D.lengthi++){
    algn[i]=(parseInt(D[i]) || D[i]==0)?10:9;
    document.write('<div id="_date'+i+'" class="css2" style="font-size:'+algn[i]+'px;color:'+dCol+'">'+D[i]+'<\/div>');
    tmpd[i]=document.getElementById("_date"+i).style;
    }
    for (
    i=0Fi++){
    document.write('<div id="_face'+i+'" class="css2" style="color:'+fCol+'">'+N[i]+'<\/div>');
    tmpf[i]=document.getElementById("_face"+i).style
    }
    for (
    i=0H.lengthi++){
    document.write('<div id="_hours'+i+'" class="css1" style="color:'+hCol+'">'+H[i]+'<\/div>');
    tmph[i]=document.getElementById("_hours"+i).style;
    }
    for (
    i=0M.lengthi++){
    document.write('<div id="_minutes'+i+'" class="css1" style="color:'+mCol+'">'+M[i]+'<\/div>');
    tmpm[i]=document.getElementById("_minutes"+i).style
    }
    for (
    i=0S.lengthi++){
    document.write('<div id="_seconds'+i+'" class="css1" style="color:'+sCol+'">'+S[i]+'<\/div>');
    tmps[i]=document.getElementById("_seconds"+i).style;         
    }
    function 
    onoff(){
    if (
    vis){ 
     
    vis=false;
     
    document.getElementById("control").value="Clock On";
     }
    else{ 
     
    vis=true;
     
    document.getElementById("control").value="Clock Off";
     
    Delay();
     }
    kill();
    }
    function 
    kill(){
    if (
    vis
     
    document.onmousemove=mouse;
    else 
     
    document.onmousemove=null;


    function 
    mouse(e){
    var 
    msy = (!ieType)?window.pageYOffset:0;
    if (!
    ewindow.event;    
     if (
    typeof e.pageY == 'number'){
      
    mouseY e.pageY ofst msy;
      
    mouseX e.pageX ofst;
     }
     else{
      
    mouseY e.clientY ofst msy;
      
    mouseX e.clientX ofst;
     }
    if (!
    viskill();
    }
    document.onmousemove=mouse;

    function 
    winDims(){
    winH=(ieType)?ieRef.clientHeight:window.innerHeight
    winW=(ieType)?ieRef.clientWidth:window.innerWidth;
    }
    winDims();
    window.onresize=new Function("winDims()");

    function 
    ClockAndAssign(){
    time = new Date();
    secs time.getSeconds();
    sec Math.PI * (secs-15) / 30;
    mins time.getMinutes();
    min Math.PI * (mins-15) / 30;
    hrs time.getHours();
    hr Math.PI * (hrs-3) / Math.PI parseInt(time.getMinutes()) / 360;

    for (
    i=0S.lengthi++){
     
    tmps[i].top=dy[D.length+F+H.length+M.length+i]+ofy+(i*han)*Math.sin(sec)+scrollY+"px";
     
    tmps[i].left=dx[D.length+F+H.length+M.length+i]+ofx+(i*han)*Math.cos(sec)+"px";
     }
    for (
    i=0M.lengthi++){
     
    tmpm[i].top=dy[D.length+F+H.length+i]+ofy+(i*han)*Math.sin(min)+scrollY+"px";
     
    tmpm[i].left=dx[D.length+F+H.length+i]+ofx+(i*han)*Math.cos(min)+"px";
     }
    for (
    i=0H.lengthi++){
     
    tmph[i].top=dy[D.length+F+i]+ofy+(i*han)*Math.sin(hr)+scrollY+"px";
     
    tmph[i].left=dx[D.length+F+i]+ofx+(i*han)*Math.cos(hr)+"px";
     }
    for (
    i=0Fi++){
     
    tmpf[i].top=dy[D.length+i]+siz*Math.sin(i*eqf*Math.PI/180)+scrollY+"px";
     
    tmpf[i].left=dx[D.length+i]+siz*Math.cos(i*eqf*Math.PI/180)+"px";
     }
    for (
    i=0D.lengthi++){
     
    tmpd[i].top=dy[i]+siz*1.5*Math.sin(-sec+i*eqd*Math.PI/180)+scrollY+"px";
     
    tmpd[i].left=dx[i]+siz*1.5*Math.cos(-sec+i*eqd*Math.PI/180)+"px";
     }
    if (!
    vis)clearTimeout(tmr);
    }

    buffW=(ieType)?80:90;
    function 
    Delay(){
    scrollY=(ieType)?ieRef.scrollTop:window.pageYOffset;
    if (!
    vis){
     
    dy[0]=-100;
     
    dx[0]=-100;
    }
    else{
     
    zy[0]=Math.round(dy[0]+=((mouseY)-dy[0])*del);
     
    zx[0]=Math.round(dx[0]+=((mouseX)-dx[0])*del);
    }
    for (
    i=1sumi++){
     if (!
    vis){
      
    dy[i]=-100;
      
    dx[i]=-100;
     }
     else{
      
    zy[i]=Math.round(dy[i]+=(zy[i-1]-dy[i])*del);
      
    zx[i]=Math.round(dx[i]+=(zx[i-1]-dx[i])*del);
     }
    if (
    dy[i-1] >= winH-80dy[i-1]=winH-80;
    if (
    dx[i-1] >= winW-buffWdx[i-1]=winW-buffW;
    }

    tmr=setTimeout('Delay()',ref);
    ClockAndAssign();
    }
    window.onload=Delay;
    }
    //-->
    </script>
    </body>
    </html> 
    Massimo

  3. #3
    Ti ringrazio moltissimo, hai risolto il mio problema.
    Ciao

    P.S.: il risultato lo trovi qui: http://pstfattrun.altervista.org/ind...i-speciali-vdm
    Consulente informatico, web designer karateca e fotografo.
    www.ferlinghetti.net
    www.karatebrescia.it

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 © 2024 vBulletin Solutions, Inc. All rights reserved.