简体   繁体   English

单击图像后全屏div

[英]Full screen div after clicking image

Can I make a div appear at full screen after clicking a image? 单击图像后可以使div以全屏显示吗? maybe with a nice fold open animation. 也许有一个很好的折叠打开动画。 I tried this without the animation: 我没有动画尝试了这个:

HTML image: HTML图片:

<span class="image fit"><a href="#" target="_blank"><img src="images/image.png" alt="image" /></a></span>

HTML Div: HTML Div:

<div id="hidden">

</div>

CSS: CSS:

#hidden {
    z-index:9999;
    display:none;
    background-color:#fff;
    position:fixed;
    height:100%;
    width:auto;
}

JS: JS:

$(document).ready(function() {
$( 'a' ).click( function() {
    $("#hidden").css("display","unset")
});
});

You need to set .css("display","block") in your JS, when you click the element, and if you wanna have it filling up the entire width and height of the window, you could look into using width: 100vw; 您需要在JS中设置.css("display","block") ,当您单击该元素时,如果要填充窗口的整个宽度和高度,则可以使用width: 100vw; and height: 100vh; height: 100vh; as this will take up the entire space available. 因为这将占用整个可用空间。

You need to replace unset to block , and add preventDefault() on click function. 您需要将unset替换为block ,并在click函数上添加preventDefault()

Check updated snippet below.. 检查下面的更新的片段。

 $(document).ready(function() { $('a').click( function(e) { e.preventDefault(); $("#hidden").show(); }); $('.close').click(function(){ $("#hidden").hide(); }) }); 
 #hidden { z-index:9999; display:none; background-color:#fff; position:fixed; height:100%; width:100%; left: 0px; top: 0px; text-align: center; } .close { position: absolute; right: 0px; top: 0px; background: #000; color: #fff; cursor: pointer; width: 30px; height: 30px; text-align: center; line-height: 30px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="image fit"><a href="#" target="_blank"><img src="images/image.png" alt="image" /></a></span> <div id="hidden"> Full Screen Div <div class="close">X</div> </div> 

If you want a simple animation. 如果要简单的动画。 Use jquery's fadeIn() method. 使用jQuery的fadeIn()方法。

$(document).ready(function({
    $( 'a' ).click( function() { 
       $("#hidden").fadeIn();
    }); 
});

You have to set your #hidden div's height and width to 100% and give it a fixed position. 您必须将#hidden div的高度和宽度设置为100%,并将其固定位置。

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

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