如何打开全屏图像(for循环+ jQuery)

Cordova - How to open to full screen an image (for loop + jQuery)

本文关键字:循环 jQuery for 何打开 图像      更新时间:2023-09-26

我将图像存储在localStorage中,该值是base64编码的图像。该函数循环遍历localStorage并获取键和值,然后jQuery将该图像追加到html中。我的问题是,我怎么能使这些生成的图像列表能够去全屏点击?

function show() {
  $( "#gallery" ).empty();
  for(var i=0, len=localStorage.length; i<len; i++) {
    var key = localStorage.key(i);
    var value = localStorage[key];
    $('#gallery').append('<img src=data:image/jpeg;base64,' + value + ' </img>');
  }
}
我希望我的问题是清楚的,这是我的第一个问题。谢谢你的回答!

jquery:

$('#gallery').on('click', 'img', function(){
  $(this).toggleClass('fullscreen');
});
css:

.fullscreen {
 position: fixed;
 top: 0;
 left: 0;
 right: 0;
 bottom: 0;
}

这将允许用户点击一个图像,如果它不是全屏的,那么让它全屏,反之亦然。

如果你特别谈论的是"点击"(比如在手机上)而不是点击,你需要让jQuery移动和替换"点击"用"点击"在jQuery代码上面。