dja*_*ngo 5 jquery jquery-isotope jquery-lazyload
ajax取出的正常同位素使用正在起作用.看工作jsfiddle.
同位素与懒惰通过ajax取不起作用.看问题jsfiddle.
问题: lazyload不会触发并继续显示灰色图像.
用于lazyload设置的javaScript:
$(document).ready(function () {
//
// initialize at ready ;
//
$container.isotope({
itemSelector: '.box',
columnWidth: function (containerWidth) {
return containerWidth / 12;
},
onLayout: function () {
$win.trigger("scroll");
}
});
//
// here i will be using data through api
// For now I am defining json manually
// var json is defined at top of this code
// considering json return was success
//$.getJSON(APIURL, function (json) {
var newElements = "";
$.each(json, function (key, value) {
console.log(key);
newElements +=
'<div class="box">' +
'<img class="lazy" src="' + small_img + '" data-originalsrc="' + value['image'] + '" width="' + value['width'] + '" height="' + value['height'] + '" />' +
'</div>';
});
var $newElems = $(newElements);
$container.append($newElems).imagesLoaded(function () {
$container.isotope('appended', $newElems);
$imgs.lazyload({
container: $container,
effect: "fadeIn",
}).removeClass("lazy");
$imgs.trigger('scroll');
});
//});
});
Run Code Online (Sandbox Code Playgroud)
我解决了。工作小提琴
导致失败的问题:
Bootstrap我也必须将 style="width:XX;height:XX" 与正常的宽度和高度参数一起放入图像标签中,以覆盖 bootstrap img{} css 定义,这是问题之一。<img class="lazy" width="200" height="300" style="width: 200px; height: 300px;" data-original="abc.jpg" src="lazygrey.gif">
AJAX 之前的 vars:由于我使用的是 ajax 内容,因此像var $imgs= $("img.lazy");ajax 调用之前那样定义的 var 不起作用。所以为了安全起见,我直接使用了 $("img.lazy") 。
| 归档时间: |
|
| 查看次数: |
2610 次 |
| 最近记录: |