SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image Preload not working

    Hi,

    I recently switched my image pre-loading to more "efficient" code I came across.

    However, it doesn't seem to be working as the images only load on mouse over.

    PHP Code:
    <script type="text/JavaScript">
    <!--
    function 
    MM_preloadImages() { //v3.0
      
    var d=document; if(d.images){ if(!d.MM_pd.MM_p=new Array();
        var 
    i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0i<a.lengthi++)
        if (
    a[i].indexOf("#")!=0){ d.MM_p[j]=new Imaged.MM_p[j++].src=a[i];}}
    }

    function 
    MM_swapImgRestore() { //v3.0
      
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function 
    MM_findObj(nd) { //v4.01
      
    var p,i,x;  if(!dd=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        
    d=parent.frames[n.substring(p+1)].documentn=n.substring(0,p);}
      if(!(
    x=d[n])&&d.allx=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(
    i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!
    && d.getElementByIdx=d.getElementById(n); return x;
    }

    function 
    MM_swapImage() { //v3.0
      
    var i,j=0,x,a=MM_swapImage.argumentsdocument.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((
    x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrcx.oSrc=x.srcx.src=a[i+2];}
    }
    //-->
    </script> 
    Could anyone point out my problem?

    Thanks.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Have you ever looked at CSS sprites?
    These don't require javascript, require less HTTP requests, and are thus overall better than javascript image switching techniques IMO.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I've never really heard of CSS sprites. What's the deal with it?

    Cheers

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,686
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by TacMaf View Post
    Thanks. I've never really heard of CSS sprites. What's the deal with it?
    Here's an intro to CSS-Sprites that should help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I will look into that.

    I had a sleep and figured out my problem to the JS, I forgot to call the preload function.

    It happens.

    Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •