Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLe Var Range
Front End Web Development Techdegree Student 18,011 PointsNeed help in making a click function that will allow me to fumble threw the image gallery I am creating.
// JavaScript Document
// appending div to the body //
var $wrapper = $("<div class='wrap'></div>");
var $photoViewer = $("<div class='photoview'></div>");
var $image = $("<img class='pic'/>");
var $arrow1 = $("<img class='arrow1' src='icon/arrows.svg'/>");
var $arrow2 = $("<img class='arrow2' src='icon/arrows-1.svg'/>");
var $textContainer = $("<div class='captionText'></div>");
var $para = $("<p></p>");
var $overlay = $("<div class='overlay'></div>");
var $main = $(".pic-nav li a");
//**************************************aPpEnDiNg ***********************************//
$photoViewer.append( $image );
$photoViewer.append($arrow1).append( $arrow2 );
$textContainer.append( $para );
$wrapper.append( $photoViewer ).append( $textContainer );
$overlay.append( $wrapper );
$("body").append( $overlay );
$overlay.hide();
/***************************************************************/
// iMaGe CliCk FuNcTiOn ShOwInG oVeRlAy //
$main.click( function(e) {
e.preventDefault();
var imageLoc = $(this).attr("href");
$image.attr("src", imageLoc);
$overlay.show();
var captionTex = $(this).children("img").attr("alt");
$para.text( captionTex );
});
/********************** cLiCk FuNcTiOn ThAt GeTs RiD Of OvErLaY ************* */
$overlay.click( function(e) {
e.preventDefault();
$overlay.hide();
});
/******************************************************************************/
$arrow1.click( function(e) {
e.preventDefault();
var $nextImageLoc = $main.attr("href", $main.children("img").attr("alt").next() );
var $nxtImg = $image.attr("src", $nextImageLoc );
});
```
``` html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="css/normalize.css"/>
<link href='https://fonts.googleapis.com/css?family=Fanwood+Text' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/grey_poupon.css"/>
<title>Photo Gallery</title>
</head>
<body>
<header class="main-head">
<input type="text" name="search" id="search" placeholder="enter a selection"/>
</header>
<div class="photo-container clearfix">
<ul class="pic-nav ">
<li><a href="img/01.jpg"><img src="img/thumb-img/01.jpg" alt="Hey Bales I love hay bales. Took this snap on a drive through the countryside past some straw fields."/></a></li>
<li><a href="img/02.jpg"><img src="img/thumb-img/02.jpg" alt="Lake The lake was so calm today. We had a great view of the snow on the mountains from here."/></a></li>
<li><a href="img/03.jpg"><img src="img/thumb-img/03.jpg" alt="Canyon I hiked to the top of the mountain and got this picture of the canyon and trees below."/></a></li>
<li><a href="img/04.jpg"><img src="img/thumb-img/04.jpg" alt=" Iceberg It was amazing to see an iceberg up close, it was so cold but didn't snow today."/></a></li>
<li><a href="img/05.jpg"><img src="img/thumb-img/05.jpg" alt="The red cliffs were beautiful. It was really hot in the desert but we did a lot of walking through the canyons"/></a></li>
<li><a href="img/06.jpg"><img src="img/thumb-img/06.jpg" alt="Fall Fall is coming. I love when the leaves on the trees start to change color."/></a></li>
<li><a href="img/07.jpg"><img src="img/thumb-img/07.jpg" alt="Plantation I drove past this plantation yesterday, everything is so green!"/></a></li>
<li><a href="img/08.jpg"><img src="img/thumb-img/08.jpg" alt="Dunes My summer vacation to the Oregon Coast. I love the sandy dunes!"/></a></li>
<li><a href="img/09.jpg"><img src="img/thumb-img/09.jpg" alt="Countryside Lane We enjoyed a quiet stroll down this countryside lane."/></a></li>
<li><a href="img/10.jpg"><img src="img/thumb-img/10.jpg" alt="Sunset Sunset at the coast! The sky turned a lovely shade of orange."/></a></li>
<li><a href="img/11.jpg"><img src="img/thumb-img/11.jpg" alt="Cave I did a tour of a cave today and the view of the landscape below was breathtaking."/></a></li>
<li><a href="img/12.jpg"><img src="img/thumb-img/12.jpg" alt="Bluebells I walked through this meadow of bluebells and got a good view of the snow on the mountain before the fog came in."/></a></li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="js/lightbox.js"></script>
</body>
</html>
1 Answer
Unsubscribed User
501 PointsHello there!
Let me suggestion something. Go to codepen.io and create a pen for your project: http://codepen.io/pen/ Add all of your code, html, css and javascript and let me know when it's done. I will help you! When you copy stuff here you can see the indentation is massed up and hard to understand the code and point out the issue.