0

我在 Page_Load() 事件中将一些图像添加到数据库中的 div 中。当您将鼠标悬停在其中一张黑白图像上时,您会看到彩色图像。我想预加载彩色图像,但在执行此操作时遇到问题。我当前的代码循环遍历所有图像,并添加以下内容:

<script type="text/javascript">
<!-- 
$(document).ready(function() { 
    $("<img />").attr("src", "%s").load(function(){ 
        $("body").append($(this)); 
    }); 
});
--></script>

to a RegisterClientScriptBockwhere%s是图像的路径。我尝试过将其附加到身体上和不附加到身体上,但似乎都不起作用。从我所见,这似乎是预加载图像的方式,但我对其他建议持开放态度。我有问题是因为我在做这件事吗?

谢谢。

4

2 回答 2

1

你有没有想过创建一个绝对定位在左上角-10000px、高/宽1px的div,然后用html把所有的图像都扔进去?我不确定为什么你需要为此使用 js。

于 2011-02-28T09:45:14.997 回答
0

也许这会有所帮助?

http://www.yourhtmlsource.com/images/preloading.html

<script type="text/javascript">
<!-- hide from non JavaScript Browsers

Image1= new Image(150,20)
Image1.src = "pic1.gif"

Image2 = new Image(10,30)
Image2.src = "pic2.gif"

Image3 = new Image(72,125)
Image3.src = "pic3.gif"

// End Hiding -->
</script>
  • Image1=new Image 是为一张图片设置新脚本效果的第一步
  • (150,20) 分别是这张图片的宽度和高度
  • Image1.src = "pic1.gif" 给出图像的来源。
于 2011-02-28T09:47:51.863 回答