Comments on code? and one question...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Marsh

    Comments on code? and one question...

    Hello,

    I fat fingered my newsreader while I was trying to post this before and I
    don't know if it's already been posted or not. I apologise if it gets
    posted more than once.

    That said...

    I've been meaning to write an image swapper like this for a while and
    finally got around to it. I'm wondering what people think of it, comments,
    suggestions, that sort of thing.

    Also, the preloadimages function isn't necessary for the image swapping
    functions but am I correct in assuming that the images being preloaded
    will speed up the image swapping the first time the page is loaded? I
    don't know if the way I'm preloading them will make them load from cache
    during the image swap or not.

    Let me know if you have any ideas.

    <SCRIPT LANGUAGE='JavaS cript'>

    var myimages = new Array();

    function preloadimages() {

    var imagelist = new Array(
    "/test/imageswap/images/test-out.gif",
    "/test/imageswap/images/test-over.gif",
    "/test/imageswap/images/test-click.gif",
    "/test/imageswap/images/test2-out.gif",
    "/test/imageswap/images/test2-over.gif",
    "/test/imageswap/images/test2-click.gif"
    );

    for (i=0; i < imagelist.lengt h; i++) {
    myimages[i] = new Image();
    myimages[i].src = imagelist[i];
    }
    }

    preloadimages() ;

    function imgonmouseover( currentimage) {
    currentimage.sr c = currentimage.sr c.substring(0, currentimage.sr c.lastIndexOf('-') + 1) + 'over' + currentimage.sr c.substring(cur rentimage.src.l astIndexOf('.') );
    }

    function imgonmouseout(c urrentimage) {
    currentimage.sr c = currentimage.sr c.substring(0, currentimage.sr c.lastIndexOf('-') + 1) + 'out' + currentimage.sr c.substring(cur rentimage.src.l astIndexOf('.') );
    }

    function imgonclick(curr entimage) {
    currentimage.sr c = currentimage.sr c.substring(0, currentimage.sr c.lastIndexOf('-') + 1) + 'click' + currentimage.sr c.substring(cur rentimage.src.l astIndexOf('.') );
    }

    </SCRIPT>

    <HTML>
    <BODY BGCOLOR='BLACK' >
    <FONT COLOR='WHITE'>
    <CENTER>
    <IMG BORDER='0' NAME='test' SRC='/test/imageswap/images/test-out.gif' ONMOUSEOVER='im gonmouseover(th is)' ONMOUSEOUT='img onmouseout(this )' ONCLICK='imgonc lick(this)'>
    <P>
    <IMG BORDER='0' NAME='test2' SRC='/test/imageswap/images/test2-out.gif' ONMOUSEOVER='im gonmouseover(th is)' ONMOUSEOUT='img onmouseout(this )' ONCLICK='imgonc lick(this)'>
    </CENTER>
    </BODY>
    </HTML>


    --
    i.m.
    All views, opinions and alleged facts expressed by this tactless moron are
    protected by the constitution of the United States of America and should be
    taken as good natured and friendly unless specifically stated otherwise.

  • Jim Ley

    #2
    Re: Comments on code? and one question...

    hOn Thu, 24 Jul 2003 15:04:08 -0500, "Ivan Marsh" <annoyed@you.no w>
    wrote:[color=blue]
    >Also, the preloadimages function isn't necessary for the image swapping
    >functions but am I correct in assuming that the images being preloaded
    >will speed up the image swapping the first time the page is loaded?[/color]

    Well that depends on the users cache settings, and your servers
    headers, it can of course slow up loading... if you get the server
    headers right, it can almost never harm.
    [color=blue]
    > "/test/imageswap/images/test-out.gif",
    > "/test/imageswap/images/test-over.gif",
    > "/test/imageswap/images/test-click.gif",[/color]

    You could constuct these the same as you do the script - loading them
    from the images in the document, so you don't need to store
    information in the script.

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    Working...