我正在尝试在新窗口中打开图像并根据 srcset 加载正确的图像,以便根据分辨率打开正确的图像大小
html:
<div class="gallery-cell">
<img alt="100%x200" data-srcset="https://farm4.staticflickr.com/3059/2835191823_e3636abb34_m.jpg 240w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_n.jpg 320w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34.jpg 500w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_z.jpg 640w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_b.jpg 1920w" data-sizes="100%" sizes="100%" srcset="https://farm4.staticflickr.com/3059/2835191823_e3636abb34_m.jpg 240w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_n.jpg 320w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34.jpg 500w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_z.jpg 640w, https://farm4.staticflickr.com/3059/2835191823_e3636abb34_b.jpg 1920w">
</div>
jQuery
$(".gallery-cell").on("click", function(e){
e.preventDefault();
var img_to_load = $(this).find('img').attr('data-srcset');
var $str = img_to_load.split(' ');
var $retina = $str[0];
imgWindow = window.open(img_to_load, 'imgWindow');
});
以上不会根据分辨率打开不同的图像,但这https://farm4.staticflickr.com/3059/2835191823_e3636abb34_m.jpg
我相信是因为$str[0];
我还没有尝试插入索引 [0],这将我带到未找到的图像