Multiple content overlay

Hello Experts,

I am using this script below to popup an overlay in a page. It works perfect.
The only issue I face for this project i am doing is  .... I need to have more than one overlay (different content) and this script only uses one.

To make it simple... i have two small images on a page. when the user click on the image the overlay should show the corresponding image in full size. This script allow my only one content overlay.

Can anyone help?



(function() {
	var triggerBttn = document.getElementById( 'trigger-overlay' ),
		overlay = document.querySelector( 'div.overlay' ),
		closeBttn = overlay.querySelector( 'button.overlay-close' );
		transEndEventNames = {
			'WebkitTransition': 'webkitTransitionEnd',
			'MozTransition': 'transitionend',
			'OTransition': 'oTransitionEnd',
			'msTransition': 'MSTransitionEnd',
			'transition': 'transitionend'
		},
		transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
		support = { transitions : Modernizr.csstransitions };

	function toggleOverlay() {
		if( classie.has( overlay, 'open' ) ) {
			classie.remove( overlay, 'open' );
			classie.add( overlay, 'close' );
			var onEndTransitionFn = function( ev ) {
				if( support.transitions ) {
					if( ev.propertyName !== 'visibility' ) return;
					this.removeEventListener( transEndEventName, onEndTransitionFn );
				}
				classie.remove( overlay, 'close' );
			};
			if( support.transitions ) {
				overlay.addEventListener( transEndEventName, onEndTransitionFn );
			}
			else {
				onEndTransitionFn();
			}
		}
		else if( !classie.has( overlay, 'close' ) ) {
			classie.add( overlay, 'open' );
		}
	}
	triggerBttn.addEventListener( 'click', toggleOverlay );
	closeBttn.addEventListener( 'click', toggleOverlay );
})();

Open in new window

RefaelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Slick812Commented:
greetings Refael, , In your code you do not show the underlying code work needed for an Overlay DIV to, I guess cover the screen in a semi-transparent dark click restriction and have some centered div (image in your case) content shown, with some close buttons.
You must use some javascript "Framework" that does the code for you in the line -
     classie.remove( overlay, 'open' );

If you are using their code work and setup, then you need to see if it can support a two content (images) overlay.

What do you want from a suggestion here from experts?
Robert SchuttSoftware EngineerCommented:
That's not much to go on but I think I found the script you used and made some changes. Note that this can be done in many ways, but I just took one possible road: make a container-div in which all images will respond to being clicked on by showing their full version (note that the small versions are just scaled down so no real thumbnails used). Some css added to make it look pretty, you can see the result here: http://schutt.nl/ee/Q_28665010/

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> EE Q_28665010 </title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<script src="js/classie.js"></script>
<script src="js/demo1.js"></script>
<style>
#trigger-container {
	margin: 50px;
	border: 3px solid green;
}
#trigger-container img {
	display: inline-block;
	margin: 10px;
	cursor: pointer;
	height: 120px;
}
div.overlay {
	text-align: center;
}
div.overlay img {
	max-width: 100%;
	max-height: 100%;
	position: relative;
	top: 50%;
	transform: translateY(-50%);
}
</style>
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style1.css" />
</head>
<body>

	<div id="trigger-container">

		<img src="http://upload.wikimedia.org/wikipedia/commons/7/70/Trefoil_aberration_PSF_OTF_and_example_image.svg">
		<img src="http://kendraleephotography.com/wp-content/uploads/2013/02/family.jpg">
		<img src="https://matsmalarkey.files.wordpress.com/2012/04/interview_informal.gif">
		<img src="http://2.bp.blogspot.com/-H3J7oGy33LI/T1d4DSIg1yI/AAAAAAAAAt8/qo7bGFq7wF4/s1600/towerr3.jpg">

	</div>
<!-- p><button id="trigger-overlay" type="button">Open Overlay</button></p -->


		<!-- open/close -->
		<div class="overlay overlay-hugeinc">
			<button type="button" class="overlay-close">Close</button>
			<img id="overlay-image" src="">
		</div>

<script>
(function() {
	var //triggerBttn = document.getElementById( 'trigger-overlay' ),
		triggerContainer = document.getElementById( 'trigger-container' ),
		overlayImage = document.getElementById( 'overlay-image' ),
		overlay = document.querySelector( 'div.overlay' ),
		closeBttn = overlay.querySelector( 'button.overlay-close' );
		transEndEventNames = {
			'WebkitTransition': 'webkitTransitionEnd',
			'MozTransition': 'transitionend',
			'OTransition': 'oTransitionEnd',
			'msTransition': 'MSTransitionEnd',
			'transition': 'transitionend'
		},
		transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ],
		support = { transitions : Modernizr.csstransitions };

	function toggleOverlayCheck(ev) {
		if (ev.target.tagName === 'IMG') {
			overlayImage.src = ev.target.src;
		}
	}

	function toggleOverlay() {
		if( classie.has( overlay, 'open' ) ) {
			classie.remove( overlay, 'open' );
			classie.add( overlay, 'close' );
			var onEndTransitionFn = function( ev ) {
				if( support.transitions ) {
					if( ev.propertyName !== 'visibility' ) return;
					this.removeEventListener( transEndEventName, onEndTransitionFn );
				}
				classie.remove( overlay, 'close' );
				overlayImage.src = '';
			};
			if( support.transitions ) {
				overlay.addEventListener( transEndEventName, onEndTransitionFn );
			}
			else {
				onEndTransitionFn();
			}
		}
		else if( !classie.has( overlay, 'close' ) ) {
			classie.add( overlay, 'open' );
		}
	}
	//triggerBttn.addEventListener( 'click', toggleOverlay );
	triggerContainer.addEventListener( 'click', toggleOverlayCheck );
	overlayImage.addEventListener( 'load', toggleOverlay );
	closeBttn.addEventListener( 'click', toggleOverlay );
})();
</script>

</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Robert SchuttSoftware EngineerCommented:
PS: I assumed the code was found here: http://tympanus.net/Development/FullscreenOverlayStyles/
but it seems that code has been re-used a number of times, not sure what the ultimate source is...

PPS: you've posted this in the jQuery topic as well, I think there must be way better jQuery plugins to do something like this but because the code you posted was not using jQuery, I decided to try and provide a solution in pure JavaScript.
RefaelAuthor Commented:
Robert Schutt yet again, thank you so much. I can work with your code and tune to fit my result :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.