Skip to content

Instantly share code, notes, and snippets.

@dtstanley
Forked from anonymous/index.css
Created June 22, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtstanley/38c15db27f90f77c0f168a898c46320d to your computer and use it in GitHub Desktop.
Save dtstanley/38c15db27f90f77c0f168a898c46320d to your computer and use it in GitHub Desktop.
null created by dtstanley - https://repl.it/GiQ2/29
* {
box-sizing: border-box;
}
main {
padding: 30px;
min-width: 250px;
}
.hero {
height: 200px;
margin-bottom: 20px;
}
.hero img {
height: 100%
}
.thumbnail {
display: inline-block;
cursor: pointer;
height: 60px;
}
a.thumbnail:hover {
box-shadow: 5px 5px 5px gray;
}
.thumbnail img {
max-height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>image carousel solution</title>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<link href="index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<main>
<h1>Image Carousel</h1>
<div class="hero">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/cat1.jpg" alt="" />
</div>
<div class="thumbnails">
<a class="thumbnail"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/cat1.jpg" alt="" /></a>
<a class="thumbnail"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/cat2.jpg" alt="" /></a>
<a class="thumbnail"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/cat3.jpg" alt="" /></a>
<a class="thumbnail"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/cat4.jpg" alt="" /></a>
</div>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</main>
<script src="index.js"></script>
</body>
</html>
//Function to identify thumbnail selected and place in main window
function handleThumbnailClicks() {
//identifies which thumbnail has been clicked
$('.thumbnail').click(function(event) {
//Sets a variable to equal the src of the image that was selected
var imgSrc = $(event.currentTarget).find('img').attr('src');
//takes the variable data (src) and replaces the hero image with it
$('.hero img').attr('src', imgSrc);
})
}
//this is the code that invokes the function above
$(function() {
handleThumbnailClicks();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment