Skip to main content
Participant
Aug 15, 2015 1:55 PM UTC
Answered

Making an image full-screen when clicked on.

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 is closed to new replies. Start a new post to keep the conversation going.
osgood_Correct answer
Legend
Aug 15, 2015 6:24 PM UTC

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>

5 replies

osgood_Correct answer
Legend
Aug 15, 2015 6:24 PM UTC

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>

Translate
Participant
Aug 24, 2015 7:24 PM UTC

thank you

Translate
Ken_Binney
Inspiring
Aug 15, 2015 5:01 PM UTC

Images stretched beyond their native size get pretty raggedy.

Are you sure that's what you want?

Translate
Nancy OShea
Community Expert
Community Expert
Aug 15, 2015 4:53 PM UTC

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.

Translate
Nancy O'Shea— Product User & Community Expert
Nancy OShea
Community Expert
Community Expert
Aug 15, 2015 5:04 PM UTC

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.

Translate
Nancy O'Shea— Product User & Community Expert