简体   繁体   English

单击时使全屏img

[英]Make an img fullscreen when clicked on

I would like to make an image full screen when clicked on. 我想在单击时使图像全屏显示。 Similar to hitting f11 in most modern browsers. 与大多数现代浏览器中的f11相似。 I've tried screenfull.js but it is really buggy and not cross browser supported that well. 我已经尝试过screenfull.js,但是它确实有问题,而且还不能很好地支持跨浏览器。

My HTML 我的HTML

 <div id="photoFrame">
   <img src="uploads/picture01.jpg" class="img" alt="PictureOne" />
   <img src="uploads/picture02.jpg" class="img" alt="PictureTwo" />
   <img src="uploads/picture03.jpg" class="img" alt="PictureThree" />
   ... and so on ...
  </div>

My CSS 我的CSS

#photoFrame {                                                       
    clear: both;
    margin-left: 0;
    width: 100vw;
    display: block;
    white-space:nowrap;
    height:auto;
    float:left;
    overflow-x:scroll;
    overflow-y: hidden;
    clear:left;
    background-color:#333;
    padding-top:40px;
    padding-bottom:40px;
}

#photoFrame img {
    width:auto;
    max-width:80%;
    height:50vh;
    overflow-x:auto;
    overflow-y: hidden;
    padding-right:10px;
    padding-left:10px;
}

Side Notes 旁注

The img class on the elements can be used by any Javascript. 元素上的img类可由任何Javascript使用。

Any help would be great or even a point in the right direction. 任何帮助都将是巨大的,甚至朝着正确方向迈出了一步。

Try something like... 尝试类似...

$(".img").click(function(){
    $(this).height($(window).height());
    $(this).width($(window).width());
});

edit 编辑
For an f11 style full screen plugin you should check out https://github.com/kayahr/jquery-fullscreen-plugin . 对于f11风格的全屏插件,您应该查看https://github.com/kayahr/jquery-fullscreen-plugin Then edit my above code to... 然后将我上面的代码编辑为...

$(".img").click(function(){
    $(this).fullScreen(true);
});

You should use a plugin like lytebox which is very simple to use and would give you a good result of what you want to achieve: 您应该使用像lytebox这样的插件,该插件使用起来非常简单,并且可以为您实现的目标带来良好的效果:

http://lytebox.com/ http://lytebox.com/

Just download the js from the above site and include that into your page 只需从上述网站下载js并将其包含在您的页面中

How to use: 如何使用:

http://lytebox.com/howTo.php http://lytebox.com/howTo.php

Its pretty simple and exactly what you want to do. 它非常简单,而且正是您想要执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM