DIV切换时背景按钮图片显示不出来的问题解决


在使用DIV+CSS做网站的时候,常常将按钮的图片做成DIV的背景,但是,这样的话,在IE中经常出现切换的时候不能顺利显示按钮背景的问题,而该问题在FF下面却不存在。

经过一段时间的摸索,发现这个问题应该可以通过预载入图片的方式解决。可以使用一个js函数将图片载入。

  1. function loadImages()
  2. {
  3.     var d=document; if(d.images)
  4.     {
  5.         if(!d.MM_p) d.MM_p=new Array();
  6.         var i,j=d.MM_p.length,a=loadImages.arguments;
  7.         for(i=0; i<a.length; i++)
  8.         {
  9.         if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
  10.         }  
  11.     }
  12. }

并使用下面的方式载入:

  1. <body class="onlyone" onLoad="loadImages('/images/index/menubt3.gif','/images/index/menubt4.gif')">

完成后,就可以顺利使用DIV切换。


感谢您的关注。您现在可以 留言(0)留下通告地址



Leave a Reply

Note: Any comments are permitted only because the site owner is letting you post, and any comments will be removed for any reason at the absolute discretion of the site owner.

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image