Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoist/9cc799fe39204e71c616 to your computer and use it in GitHub Desktop.
Save egoist/9cc799fe39204e71c616 to your computer and use it in GitHub Desktop.
图片由于缓存所以不会每次使用 .load() 都会有效果 【解决方案】
var el = $('img');
el.one("load", function() {
//do something, for me I wanna make the position vertical center, so I call function center();
}).each(function() {
if(this.complete) $(this).load();
});
/*
function center(){
var marginTop = 0;
if($(this).height()>253){
marginTop = ($(this).height()-253) /2;
marginTop = '-'+marginTop+'px';
}
$(this).css('margin-top',marginTop);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment