对于我的博客http://seans.ws,我编写了一个查看图像大小的脚本,如果它比默认容器大小更宽,它会计算出它需要多少负边距才能将其与其余部分居中的内容。
这很好用,但是我通过无限滚动加载了图像,并且它们不受我的脚本的操纵。
我的无限滚动js:http ://static.tumblr.com/q0etgkr/ytzm5f1ke/infinitescrolling.js
$(window).load(function() {
var centerBigImages = $(function() {
$('img').css('marginLeft', function(index, value){
if($(this).width() > 660) {
return -($(this).width() - 660)/2;
}
return value;
});
});
centerBigImages();
我在 IE 中查看了这个DOMNodeInserted 等效项?,但这有点超出我的 js newb 头:(