简体   繁体   English

justifiedGallery:屏幕 <800px 时尝试更改图像路径

[英]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.

相关问题 我想移动左导航栏菜单 <div> 屏幕尺寸为800px时返回顶部 - I want to move my Left nav bar menu <div> to Top when the screen size is 800px 原型:滚动页面800px时显示元素 - prototype: show a element when scroll page pased 800px 当我的窗口宽度小于800px时,如何将js滑块效果更改为淡入淡出? - how do i change the js slider effect to fade when my window width is less than 800px? 当浏览器的尺寸小于800px时如何隐藏div - How to hide div when browser resizes to less than 800px 仅当最小宽度为800px时才执行Javascript - Executing Javascript only if min-width is 800px FB时间轴应用高度停留在800px - FB Timeline App Height Stuck at 800px 如果窗口宽度大于800px时刷新站点,则jQuery click事件不起作用 - jQuery click event doesn't work if I refresh site when window width is bigger than 800px 如果窗口宽度在800px至799px之间,则执行JS函数 - Do JS function if window width between 800px and 799px JS-窗口的宽度从高于800px的像素数量减少到800px以下导致触发动作 - JS - Window's width being decreased below 800px from an amount of pixels that are higher than 800px causes an action to trigger Javascript-如果窗口宽度&lt;= 800px,则将活动链接移至导航顶部 - Javascript - Move active link to top of navigation if window-width <= 800px
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM