Skip to main content
Participant
August 15, 2015
Answered

Making an image full-screen when clicked on.

  • August 15, 2015
  • 3 replies
  • 24660 views

I wish to make my images full screen available,so when you click on it the image enlarges and it comes to the center possibly.

When you are finished looking on the picture you can close it by pressing the "X".

How is this possible?

Thank you

This topic has been closed for replies.
Correct answer osgood_

Fullscreen example below - simple bit of jQuery. I've used the same sized image for the thumbnail and large image for the example but to save on bandwidth reduce the size of the thumbnail images.

<!DOCTYPE>

<html>

<head>

<meta ="charset=UTF-8" />

<title>Full Screen Gallery</title>

<style>

html {

height: 100%;

}

body {

font-family: helvetica, sans-serif;

height: 100%;

margin: 100px 0;

}

.photo-overlay {

    height: 100%;

    width: 100%;

    position: absolute;

    top: 0;

    left: 0;

    background-color:#9F3;

    background-size: cover;

    }

    .close-photo-overlay {

    font-size: 30px;

    position: absolute;

    right: 50px;

    top: 50px;

    color: #fff;

    z-index: 2;

    padding: 6px 9px;

    border: 1px solid #fff;

    }

.imgBox {

    width: 20%;

    margin: 0 auto;

}

img {

    max-width: 100%;

    height: auto;

    padding: 0 0 15px 0;

}

</style>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

<script>

$(document).ready(function() {

$('.photo-overlay').hide();

$('.thumb').click(function(event) {

event.preventDefault();

var imageUrl = $(this).attr('href');

$('.photo-overlay').show().css('background-image', 'url(' + imageUrl + ')');

});

$('.close-photo-overlay').css('cursor' , 'pointer').click(function() {

$('.photo-overlay').hide();                                                                                                   

});

});

</script>

</head>

<body>

<div class="photo-overlay">

<div class="close-photo-overlay"><i class="fa fa-times"></i>

</div>

<!-- end close-photo-overlay -->

</div>

<!-- end photo-overlay -->

<div class="imgBox">

<a href="https://upload.wikimedia.org/wikipedia/commons/6/63/Monarch_In_May.jpg" class="thumb"><img src="https://upload.wikimedia.org/wikipedia/commons/6/63/Monarch_In_May.jpg" /></a>

</div>

<!-- end imgBox -->

<div class="imgBox">

<a href="http://cdn.funcheap.com/wp-content/uploads/2011/06/Butterfly_Beauty.jpg" class="thumb"><img src="http://cdn.funcheap.com/wp-content/uploads/2011/06/Butterfly_Beauty.jpg" class="thumb"/></a>

</div>

<!-- end imgBox -->

</body>

</html>

3 replies

osgood_Correct answer
Legend
August 15, 2015

Fullscreen example below - simple bit of jQuery. I've used the same sized image for the thumbnail and large image for the example but to save on bandwidth reduce the size of the thumbnail images.

<!DOCTYPE>

<html>

<head>

<meta ="charset=UTF-8" />

<title>Full Screen Gallery</title>

<style>

html {

height: 100%;

}

body {

font-family: helvetica, sans-serif;

height: 100%;

margin: 100px 0;

}

.photo-overlay {

    height: 100%;

    width: 100%;

    position: absolute;

    top: 0;

    left: 0;

    background-color:#9F3;

    background-size: cover;

    }

    .close-photo-overlay {

    font-size: 30px;

    position: absolute;

    right: 50px;

    top: 50px;

    color: #fff;

    z-index: 2;

    padding: 6px 9px;

    border: 1px solid #fff;

    }

.imgBox {

    width: 20%;

    margin: 0 auto;

}

img {

    max-width: 100%;

    height: auto;

    padding: 0 0 15px 0;

}

</style>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

<script>

$(document).ready(function() {

$('.photo-overlay').hide();

$('.thumb').click(function(event) {

event.preventDefault();

var imageUrl = $(this).attr('href');

$('.photo-overlay').show().css('background-image', 'url(' + imageUrl + ')');

});

$('.close-photo-overlay').css('cursor' , 'pointer').click(function() {

$('.photo-overlay').hide();                                                                                                   

});

});

</script>

</head>

<body>

<div class="photo-overlay">

<div class="close-photo-overlay"><i class="fa fa-times"></i>

</div>

<!-- end close-photo-overlay -->

</div>

<!-- end photo-overlay -->

<div class="imgBox">

<a href="https://upload.wikimedia.org/wikipedia/commons/6/63/Monarch_In_May.jpg" class="thumb"><img src="https://upload.wikimedia.org/wikipedia/commons/6/63/Monarch_In_May.jpg" /></a>

</div>

<!-- end imgBox -->

<div class="imgBox">

<a href="http://cdn.funcheap.com/wp-content/uploads/2011/06/Butterfly_Beauty.jpg" class="thumb"><img src="http://cdn.funcheap.com/wp-content/uploads/2011/06/Butterfly_Beauty.jpg" class="thumb"/></a>

</div>

<!-- end imgBox -->

</body>

</html>

Participant
August 24, 2015

thank you

Ken_Binney
Inspiring
August 15, 2015

Images stretched beyond their native size get pretty raggedy.

Are you sure that's what you want?

Nancy OShea
Community Expert
Community Expert
August 15, 2015

This is done with JavaScript or jQuery Modal Windows -- sometimes called Lightboxes.  See links below.

fancyBox - Fancy jQuery Lightbox Alternative

Bootstrap components: modal window

http://www.w3schools.com/bootstrap/bootstrap_modal.asp

Nancy O.

Nancy O'Shea— Product User & Community Expert
Nancy OShea
Community Expert
Community Expert
August 15, 2015

I should have added to my reply that you must use 2 sets of images in your modal window.  A thumbnail size image linked to the full size image.

Nancy O.

Nancy O'Shea— Product User & Community Expert