【问题标题】:How do I add different sizes of the same image to a homepage banner in my media queries when the banner image is stored in javascript?当横幅图像存储在 javascript 中时,如何在我的媒体查询中将不同尺寸的同一图像添加到主页横幅?
【发布时间】:2018-02-12 04:45:04
【问题描述】:

这是我的横幅图像存储的地方,在 javascript 中:

```

/*
    Background slideshow
*/
$('.top-content').backstretch("assets/img/backgrounds/Banner_1024 x 768.jpg");
$('.testimonials-container').backstretch("assets/img/backgrounds/testimonial1.jpg");

$('a[data-toggle="tab"]').on('shown.bs.tab', function(){
$('.testimonials-container').backstretch("resize");
});

```

我想为移动设备和其他屏幕尺寸添加另一个版本的横幅图像。我是否将它们添加到这里的 javascript 中?如何链接媒体查询中的所有内容?

【问题讨论】:

  • 不同的版本意味着不同的图像或不同的大小?
  • @mathur 相同的图像,但不同的尺寸/作物。

标签: javascript css jquery-backstretch


【解决方案1】:

您正在使用 jQuery 插件 Backstretch。

快速查看https://github.com/jquery-backstretch/jquery-backstretch 的文档表明这是一个内置功能。只需传递一组图像和宽度。

// Or, to automatically choose from a set of resolutions.
// The width is the width of the image, and the algorithm chooses the best fit.
$(".foo").backstretch([
  [
    { width: 1080, url: "path/to/image1_1080.jpg" },
    { width: 720, url: "path/to/image1_720.jpg" },
    { width: 320, url: "path/to/image1_320.jpg" }
  ]
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多