1

是否可以在调整大小时使交换基础 6 替换属性data-src上的路径而不是图像的src

在 DIV 中的背景图像上具有相同的行为,将data-src上的路径替换为style="background-image

我试图仅在视口上显示图像,某种使用交换的手动延迟加载。

页面加载时我正在删除 src:

/*Stop Interchange Background Images loading images*/

    $(".delay").each(function(){
        var img_src = $(this).attr('src');
        $(this).attr("data-src", img_src);
        $(this).attr('src', '');
    });

/*Stop Interchange Background Images loading for DIVs and Slides*/

    $(".backImg").each(function(){
        var img_backImg = $(this).css('background-image');
        $(this).attr("data-src", img_backImg);
        $(this).css('background-image','');
    });

然后,一旦图像接触视口,就会添加 src 或背景图像。这运作良好,但我现在的问题是图像在调整大小时自动出现。

因此,如果 Interchange 使用data-src更改url,我可以获取 URL 并将其粘贴到我需要的位置。

希望这对可以帮助我的人有意义。

非常感谢!

4

1 回答 1

2

回答我自己的问题:

我找到了一种不美观的方法,但效果很好:

编辑foundation.js文件:

第 6253 行:

this.$element.attr('src', path).load(function () {

代替:

this.$element.attr('data-original', path).load(function () {

第 6259 行(用于背景图像):

this.$element.css({ 'background-image': 'url(' + path + ')' }).trigger(trigger);

更换:

this.$element.attr('data-original', path).load(function () {
            _this.currentPath = path;
          }).trigger(trigger);
于 2016-11-04T17:09:46.777 回答