[英]justifiedGallery : Trying to change image path when screen <800px
My Justified Gallery is very slow to load on smartphone, so I would like to change the image path when screen is < 800px.我的 Justified Gallery 在智能手机上加载非常慢,所以我想在屏幕小于 800 像素时更改图像路径。 The new path has smaller images (h350 instead of h450).新路径具有较小的图像(h350 而不是 h450)。
I've been trying like this我一直在尝试这样
<div id="alldrawings">
<div>
<a class="group1" href="img/drawing/poisson-serigraphie.jpg"><img alt="poisson" src="img/h450/poisson-serigraphie.jpg"/></a>
<div class="caption">Poisson, Sérigraphie, 2020<br /><a href="contact.html" class="forsale">A4 5€ / A3 8€</a></div>
</div>
<div>
<a class="group1" href="img/drawing/bee-serigraphie.jpg"><img alt="abeille" src="img/h450/bee-serigraphie.jpg"/></a>
<div class="caption">Abeille, Sérigraphie, 2020<br /><a href="contact.html" class="forsale">36x25cm 8€ / 45x33cm 15€ / 56x40cm 20€</a></div>
</div>
<!-- and so on ... -->
</div>
$(function() {
var width = $(window).width();
if (width < 800) {
$("#alldrawings img").each(function(index){
var src = $(this).attr("src")
var photoName = src.substr(src.lastIndexOf("/"));
$(this).attr("src", "img/h350/"+photoName)
})
}
else{
$("#alldrawings img").each(function(index){
var src = $(this).attr("src")
var photoName = src.substr(src.lastIndexOf("/"));
$(this).attr("src", "img/h450/"+photoName)
})
}});
<!-- JUSTIFIED GALLERY -->
$('#alldrawings').justifiedGallery({
rowHeight: 280,
maxRowHeight: 450,
lastRow: 'nojustify',
margins : 8,
});
The result (that you can see here the test page ) is that changing path is working, but then JustifiedGallery is not working properly.结果(您可以在此处看到测试页面)是更改路径正在工作,但是 JustifiedGallery 无法正常工作。 Normally it should preload images before to show the gallery, row by row.通常它应该在显示画廊之前预加载图像,逐行显示。 But in this case it is first showing all the page with the 'alt' image content and then images appear in random order, and it's not beautiful.但在这种情况下,它首先显示所有带有“alt”图像内容的页面,然后图像以随机顺序出现,并不美观。 I don't know how to proceed to fix it.我不知道如何着手修复它。
Thank you for any help感谢您的任何帮助
Thanks, I managed to make it work with IMG SRCSET on Firefox, but not on Chrome (ignoring it).谢谢,我设法使它与 Firefox 上的 IMG SRCSET 一起工作,但不能在 Chrome 上工作(忽略它)。 I found many topics about this issue.我发现了很多关于这个问题的话题。 All say I've to empty the cache, but even with an empty cache, Chrome v65 is ignoring the srcset...所有人都说我必须清空缓存,但即使缓存为空,Chrome v65 也会忽略 srcset ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.