开发者

ASP.Net load pictures after background

I have an CSS Style and a page with 6 pics. When I open a normal page, all loads okay. When I open the page with the pics, the pics will load at the same time as the background and it needs a few seconds.

How to delay the开发者_高级运维 picture-loading or set it a lower prio then the bg / design?


You can use this jQuery plugin for lazy loading images.

Lazy Load: Image lazy loader plugin for jQuery


Your css is embed to page with help of <link tag. On other hand it can have event 'onload'. So put it together and load picture after css has been loaded. To locate css-link from asp code use:

    ControlCollection headerControls = Page.Header.Controls;
    for (int i = headerControls.Count - 1; i >= 0; i--)
    {
        HtmlLink link = headerControls[i] as HtmlLink;
        if (link != null 
          && String.CompareOrdinal(link.Attributes["rel"], "stylesheet") == 0)
        {
            if (...) //add compare with your CSS name here
                link.Attributes["onclick"] = ...//add jscript to load image;
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜