开发者

jQuery, image loading events

i'm building a jQuery Plugin to turn a div full of <img /> into a gallery. I ran into a problem, i can't seem to solve:

right now, i call the plugin on document ready so, for a few 10ths of a second, i can see all the images at the same time, before i hide() all but the first one.

the plugin works this way:

$(function(){$('div').gallery();});  

and 开发者_C百科in the plugin:

$(this).find('img').wrap('<div />').hide();
$(this).find('img:first').show();

does anyone have any suggestions?

Thanks


If I want to hide stuff for browsers that support js I find that the best way is to

<body>
  <script>document.body.className = "js";</script>

Then you could just hide stuff in your css

body.js .mygalleryimagesdiv {
  display: none;
}

And show them when you're ready in the script... This is the only non unobtrusive script i allow myself to write :)


You have no control over when the user of your plugin calls it.

He/she may delay calling it for seconds or minutes after the page has loaded along with all the images. So it is up to him/her to hide the images e.g. via CSS: {display: none}.


You should initially hide the images preferably via CSS or by using inline styles. You can then show them via jQuery.show() or jQuery.css() methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜