我创建了一个水平div,它容纳了大量的图像,但有一个固定的宽度,所以你必须滚动才能看到所有的图像。我试图实现延迟加载,以加快加载时间,但我可以让它在前几个图像上工作,但不是其他图像只是保持灰色。
当我删除white-space:nowrap;我可以得到延迟加载工作正确,但我失去了我的单行div。
什么是一个很好的方法,让水平滚动div工作与延迟加载?
<div class="galleryContainer container-fluid list-inline">
<div class="row ">
<?php
$files = glob("public/img/thumbnail/*.*");
$lFiles = glob("public/img/*.*");
for ($i=0; $i<count($files); $i++)
// ($i=0; $i<count($lFiles); $i++)
{
$image = $files[$i];
$Limage = $lFiles[$i];
// print $image ."<br />";
echo "<div class='img-responsive col-md-3'>";
echo '<div class="container" width: 90%">';
echo '<a href="../'.$Limage .'">
<img width:"300px" height="400px" height="class="lazy" data-original="../'.$image .'" alt="Mural Image"/></a>';
echo '</div>';
echo '</div>';
}
?>
</div>
</div>
<script>
jQuery(document).ready(function ($) {
$(function() {
$("img.lazy").lazyload();
container: $(".galleryContainer")
threshold : 200
effect : "fadeIn"
});
});
</script>
<script src="../public/scripts/jquery.lazyload.js"></script>
<script src="../public/scripts/jquery.scrollstop.js"></script>
这是我的CSS:
.galleryContainer {
margin-top: 2%;
width: 90%;
overflow-x:scroll;
overflow-y:hidden;
}
.profile {
margin-top: 5%;
}
}
.galleryContainer img {
height: 300px;
width: 400px;
}
.fullDrawing img{
height: 217.273px;
width:1440px;
}
.list-inline {
white-space:nowrap;
}
.galleryContainer > .row [class*="col-lg"], .galleryContainer > .row [class*="col-md"], .galleryContainer > .row [class*="col-md"] {
float:none;
display:inline-block;
white-space:normal;
vertical-align:top;
}
#main-content > .row {
overflow-x:scroll;
overflow-y:hidden;
white-space:nowrap;
}
先做一些小改动:
<img width:"300px" height="400px" height="class="lazy" data-original="../'.$image .'" alt="Mural Image"/>';
<img class="lazy" data-original="../'.$image .'" width:"300" height="400" alt="Mural Image">';
我也从来没有在html中包含我的php脚本,但可能是lazy load函数触发太早了。看看浏览器加载的代码,如果函数被正确触发,元素应该是这样的:
<img class="lazy" data-original="PATH" width="300" height="400" alt="Mural Image" src="PATH" style="display: inline;">
最后但并非最不重要的是,lazyload可能会在图像周围的链接中出现问题,您应该使用原始图像进行测试。