循环加载的p结构:
Sunset Lake
A peaceful sunset view...
加载完成执行的JS:
$(function(){
$('.img_load').each(function() {
$(this).load(function(){
if( $(this).height() > 300){
//显示
$(this).parent().parent().next().css('display', 'block');
}
});
});
});
但是这只是进入页面是加载数据有用,而通过ajax
$.ajax({
……
})
.done(function(data){
……
$.each(pics, function(index, val){
var add =
"" +
"
" +
"
" +
"
" +
"" +
""+ this.object +"" +
"" +
"
"+ this.words +"
" +
"" +
""+
"";
$("#contain").append(add);
//判断
高度并修改状态
var img = new Image();
img.src = this.url;
img.onload = function(){
var height = img.height;
if( height > 300){
$(add).find('.stop').css('display', 'block');
}
};
});
……
});
动态加载的数据则不会去执行之前的JS函数。通过Image()的onload()函数虽然可以取到高度,但是还是无法修改的显示状态。望大神帮忙解答!
效果(太高的图片底部有变化):
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
找到问题了,自己傻了,ajax请求漏了一层a标签。