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 trial
William Mackay
25,189 PointsJavaScript Gallery
I have an html file, a css file, and a javascript file. I want to write a function that will pick one of the 3 pictures and show them in the "image" div. When I mouseover it and for it to return to what it was before, when I mouse out but I'm not sure what to do. Any help would be appreciated.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Photo Gallery</title>
<link rel="stylesheet" href="css/gallery.css">
<script src = "js/gallery.js"></script>
</head>
<body>
<div id = "image">
Hover over an image below to display here.
</div>
<img class = "preview" alt = "Styling with a Bandana" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon.jpg" onmouseover = "upDate(this)" onmouseout = "unDo()">
<img class = "preview" alt = "With My Boy" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon2.JPG" onmouseover = "upDate(this)" onmouseout = "unDo()">
<img class = "preview" src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/389177/bacon3.jpg" alt = "Young Puppy" onmouseover = "upDate(this)" onmouseout = "unDo()">
<script src="js/index.js"></script>
</body>
</html>
body {
margin: 2%;
border: 1px solid black;
background-color: #b3b3b3;
}
#image{
line-height:650px;
width: 575px;
height: 650px;
border:5px solid black;
margin:0 auto;
background-color: #8e68ff;
background-image: url('');
background-repeat: no-repeat;
color:#FFFFFF;
text-align: center;
background-size: 100%;
margin-bottom:25px;
font-size: 150%;
}
.preview{
width:10%;
margin-left:17%;
border: 10px solid black;
}
img {
width:95%;
}
function upDate(previewPic){
/* In this function you should
1) change the url for the background image of the div with the id = "image"
to the source file of the preview image */
var imgArray = new Array(3);
for (img in imgArray) {
previewPic = document.getElementsByClassName("preview").src;
document.getElementById("image").innerHTML("<img src " + imgArray[i] + ">")
}
/*
2) Change the text of the div with the id = "image"
to the alt text of the preview image
*/
for (img in imgArray) {
document.getElementById("image").innterHTML()
}
}
function unDo(){
/* In this function you should
1) Update the url for the background image of the div with the id = "image"
back to the orginal-image. You can use the css code to see what that original URL was
2) Change the text of the div with the id = "image"
back to the original text. You can use the html code to see what that original text was
*/
}
William Mackay
25,189 PointsWilliam Mackay
25,189 PointsI think I figured it out. Thanks.