Trouble converting STYLE tags to CLASS tags using an external CSS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michellevt
    New Member
    • Feb 2008
    • 1

    Trouble converting STYLE tags to CLASS tags using an external CSS

    Hi

    I am working on a project (for college) and wondered if anyone can help me with my problem. In the project we are not allowed to make use of any "style" attributes but "class" attributes instead. The following is the java script that i am using and i am having trouble in using a class instead of a style tag because simply replacing the style=\"positio n:absolute;\" tag with class=\"posiAbs \" where in the external css ".posiAbs {position:absol ute;} doesn't work. I am very new to this stuff so if anyone has some advice I would really appreciate it.

    NOTES: This script only has to be compatible with Internet Explorer

    JAVA SCRIPT

    [CODE=javascript]
    var titlea = new Array();
    var texta = new Array();
    var heightarr = new Array();

    titlea[0] = "<img src=\"doggie3.j pg\"> Dog Fact #1";
    texta[0] = "It is a myth that dogs are color blind. They can actually see in color, just not as vividly as humans. It is akin to our vision at dusk.";

    titlea[1] = "<img src=\"doggie3.j pg\"> Dog Fact #2";
    texta[1] = "Dogs DO have better low-light vision than humans because of a special light-reflecting layer behind their retinas ";

    titlea[2] = "<img src=\"doggie3.j pg\"> Dog Fact #3";
    texta[2] = " A German Shepherd guide dog led her blind companion the entire 2100 mile Applachian Trail ";

    titlea[3] = "<img src=\"doggie3.j pg\"> Dog Fact #4";
    texta[3] = "If never spayed or neutered, a female dog, her mate, and their puppies could product over 66,000 dogs in 6 years! ";

    var mc=4;

    var inoout=false;
    var tmpv;
    tmpv=180-8-8-2*parseInt(1);
    var psy = new Array();
    divtextb ="<div id=d";divtextb2 ="<div id=dz";divtev1= " onmouseover=\"p auseScroller("; divtev2=")\" onmouseout =\"restime(";di vtev3=")\" ";divtev4="";di vtexts = " style=\"positio n:absolute;visi bility:hidden;w idth:"+tmpv+"; COLOR: #000000; left:0; top:0; FONT-FAMILY: MS Sans Serif,arial,hel vetica; FONT-SIZE: 10pt; FONT-STYLE: normal; FONT-WEIGHT: normal; TEXT-DECORATION: none; margin:0px; overflow-x:hidden; LINE-HEIGHT: 12pt; text-align:left;padd ing:0px; cursor:'default ';\">";ie6span = " style=\"positio n:relative; COLOR: #5700AE; width:"+tmpv+"; FONT-FAMILY: verdana,arial,h elvetica; FONT-SIZE: 11pt; FONT-STYLE: normal; FONT-WEIGHT: bold; TEXT-DECORATION: none; LINE-HEIGHT: 14pt; text-align:left;padd ing:0px;\"";uzu n="<div id=\"enuzun\" style=\"positio n:absolute;\">" ;
    uzun2="<div id=\"enuzun2\" style=\"positio n:absolute;left :0;top:0;\">";
    var thetop=0;
    var toplay=0;

    function pauseScroller(g num,gnum5) {
    inoout=true;
    objd=eval("d"+g num);
    objd2=eval("hgd "+gnum);
    window.status=" The Coolest Dog Facts in Town!!!!! :-)";
    }

    function restime(gnum2,g num5) {
    inoout=false;
    if(gnum5==1) {
    objd=eval("dz"+ gnum2);
    objd2=eval("hgd z"+gnum2);
    } else {
    objd=eval("d"+g num2);
    objd2=eval("hgd "+gnum2);
    }
    objd.style.colo r="#000000";
    objd2.style.col or="#5700AE";
    window.status=" ";
    }

    function dotrans() {
    if(inoout==fals e) {
    theTop--;
    if(theTop<(-1*toplay)) {
    theTop=0;
    enuzun2.style.p ixelTop=400;
    }
    enuzun.style.pi xelTop=theTop;
    if((theTop+topl ay)<400) {
    enuzun2.style.p ixelTop=theTop+ toplay;
    }
    }
    if(psy[(theTop*(-1))+4]==3) {
    setTimeout('dot rans()',3000+35 );
    } else {
    setTimeout('dot rans()',35);
    }
    }

    function scroller2() {
    for(i=0;i<mc;i+ +) {
    objd=eval("d"+i );objd2=eval("d z"+i);
    if((parseInt(ob jd.offsetHeight )<=0)||(parseIn t(objd2.offsetH eight)<=0)) {
    setTimeout('scr oller2()',1000) ;return;
    }
    }
    i=0;
    for(i=0;i<mc;i+ +) {
    objd=eval("d"+i );
    heightarr[i]=parseInt(objd. offsetHeight);
    }
    toplay=4;
    for(i=0;i<mc;i+ +) {
    objd=eval("d"+i );objd2=eval("d z"+i);
    objd.style.visi bility="visible ";
    objd2.style.vis ibility="visibl e";
    objd.style.pixe lTop=toplay;
    objd2.style.pix elTop=toplay;
    psy[toplay]=3;
    toplay=toplay+h eightarr[i]+10;
    }
    enuzun.style.le ft=8+"px";
    enuzun.style.he ight=toplay+"px ";
    enuzun.style.wi dth=tmpv+"px";
    enuzun.style.to p=400+"px";
    enuzun2.style.l eft=8+"px";
    enuzun2.style.h eight=toplay+"p x";
    enuzun2.style.w idth=tmpv+"px";
    enuzun2.style.t op=400+"px";
    theTop=400;
    dotrans();
    }

    function scroller() {
    i=0;
    innertxt=""+uzu n;
    for(i=0;i<mc;i+ +) {
    innertxt=innert xt+""+divtextb+ ""+i+""+divtev1 +i+",0"+divtev2 +i+",0"+divtev3 +i+divtev4+divt exts+"<span id=\"hgd"+i+"\" "+ie6span+">"+t itlea[i]+"</span><br>"+text a[i]+"</div>";
    }
    innertxt=innert xt+"</div>";
    innertxt=""+inn ertxt+uzun2;
    for(i=0;i<mc;i+ +) {
    innertxt=innert xt+""+divtextb2 +""+i+""+divtev 1+i+",1"+divtev 2+i+",1"+divtev 3+i+divtev4+div texts+"<span id=\"hgdz"+i+"\ ""+ie6span+">"+ titlea[i]+"</span><br>"+text a[i]+"</div>";
    }
    innertxt=innert xt+"</div>";spageie.i nnerHTML=""+inn ertxt;setTimeou t('scroller2()' ,500);
    }
    window.onload=s croller;
    [/CODE]

    HTML PAGE:

    [html]
    <html>
    <head>
    <title>
    </title>
    </head>
    <body bgcolor="#8080F F">
    <div id="disspageie" >
    <div id="spageie">
    </div>
    </div>
    <script language="javas cript">
    document.write( "<script language=\"java script\" src=\"navigatio nBarScrollerJav aScript.js\"></scr"+"ipt>");
    </script>
    </body>
    </html>

    [/html]
    Last edited by drhowarddrfine; Feb 20 '08, 02:33 PM. Reason: Removed bold texting
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    Well, at least it will not work in a browser that is not IE, which seems to be the idea.

    Any style assignment you make in a class in a stylesheet will work exactly like an inline style, but classes are trumped by inline styles, by more specific selectors in the cascade, and by any user stylesheet declarations.

    You could try making your classes more specific, targetting element tags as well as classnames, but really specific classes could be set on id selectors.

    Comment

    • drhowarddrfine
      Recognized Expert Expert
      • Sep 2006
      • 7434

      #3
      I'm pretty sure the issue is properly inserting the styling using javascript, so this is a javascript question and I'm sending it there.

      btw, JavaScript is one word, not two, and totally unrelated to Java.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by Michellevt
        I am working on a project (for college)...
        NOTES: This script only has to be compatible with Internet Explorer
        A bit off-topic, but is that what they're teaching you?

        Comment

        Working...