I have the below page for an image gallery which when you hover over the image, the description slides out and image enlarges. It works fine. However I wondered, rather than having to hover over with mouse I would like to visit the page and a random image in the gallery enlarges and description slides out and returns to normal, then moving onto another image and to the next. So just to clarify as you visit the page:
- In random order an image from the gallery enlarges and description slides out, then returns to original state before moving onto next image.
- Next random image in the gallery enlarges and description slides out and so on
All in random order.
$(function() {
// View the selected photo at full size
$(".photo-image").click(function() {
$(this).addClass("photo-selected");
$(this).parent().addClass("photo-x");
$("#overlay").show();
});
// Close the full size view when #overlay is clicked
$("#overlay").click(function() {
$(".photo-image").removeClass("photo-selected");
$(".photo-x").removeClass("photo-x");
$("#overlay").hide();
});
});
// Close full size view if "esc"
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$(".photo-image").removeClass("photo-selected");
$("#overlay").hide();
}
});
#container {
width: 850px;
position: relative;
margin: 0 auto;
top: 50px;
}
#overlay {
cursor: pointer;
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #000;
opacity: .7;
z-index: 2000;
display: none;
}
.photo {
position: relative;
float: left;
height: 100px;
width: 100px;
}
.photo-image {
cursor: pointer;
position: relative;
top: 1px;
left: 1px;
width: 100px;
border: 1px solid #999;
z-index: 1000;
opacity: 0.6;
transition: width 1s, top 1s, left 1s, opacity 1s, z-index .01s;
}
.photo-image:hover {
width: 200px;
top: -50px;
left: -50px;
z-index: 1001;
opacity: 1;
}
.photo-selected {
cursor: default;
z-index: 2001;
width: 500px;
opacity: 1;
top: -20px;
left: -200px;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}
.photo-selected:hover {
width: 500px;
top: -50px;
left: -50px;
z-index: 2001;
opacity: 1;
top: -20px;
left: -200px;
}
.imagepluscontainer div.desc {
/* CSS for desc div of each image. */
position: absolute;
width: 90%;
z-index: 1;
/* Set z-index to that less than image's, so it's hidden beneath it */
bottom: 0;
/* Default position of desc div is bottom of container, setting it up to slide down */
left: 5px;
padding: 8px;
background: rgba(0, 0, 0, 0.8);
/* black bg with 80% opacity */
color: white;
-moz-border-radius: 0 0 8px 8px;
/* CSS3 rounded borders */
-webkit-border-radius: 0 0 8px 8px;
border-radius: 0 0 8px 8px;
opacity: 0;
/* Set initial opacity to 0 */
-moz-box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
/* CSS3 shadows */
-webkit-box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
-moz-transition: all 0.5s ease 0.5s;
/* Enable CSS3 transition on desc div. Final 0.5s value is the delay before animation starts */
-webkit-transition: all 0.5s ease 0.5s;
-o-transition: all 0.5s ease 0.5s;
-ms-transition: all 0.5s ease 0.5s;
transition: all 0.5s ease 0.5s;
}
.imagepluscontainer div.desc a {
color: white;
}
.imagepluscontainer:hover div.desc {
/* CSS for desc div when mouse hovers over main container */
-moz-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
-ms-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
transform: translate(0, 100%);
opacity: 1;
/* Reveal desc DIV fully */
}
/*### Below CSS when applied to desc DIV slides the desc div from the right edge of the image ###*/
.imagepluscontainer div.rightslide {
width: 200px;
/* reset from default */
height: 100px;
top: -50px;
right: -50px;
left: auto;
/* reset from default */
bottom: auto;
/* reset from default */
padding-left: 15px;
-moz-border-radius: 0 8px 8px 0;
-webkit-border-radius: 0 8px 8px 0;
border-radius: 0 8px 8px 0;
}
.imagepluscontainer:hover div.rightslide {
-moz-transform: translate(100%, 0);
-webkit-transform: translate(100%, 0);
-ms-transform: translate(100%, 0);
-o-transform: translate(100%, 0);
transform: translate(100%, 0);
z-index: 2001;
}
/*### Below CSS when applied to desc DIV slides the desc div from the left edge of the image ###*/
.imagepluscontainer div.leftslide {
width: 280px;
/* reset from default */
height: 185px;
top: 0px;
left: -100;
bottom: auto;
/* reset from default */
padding-left: 15px;
-moz-border-radius: 8px 0 0 8px;
-webkit-border-radius: 8px 0 0 8px;
border-radius: 8px 0 0 8px;
z-index: 2001;
}
.imagepluscontainer:hover div.leftslide {
-moz-transform: translate(-100%, 0);
-webkit-transform: translate(-100%, 0);
-ms-transform: translate(-100%, 0);
-o-transform: translate(-100%, 0);
transform: translate(-100%, 0);
}
/*### Below CSS when applied to desc DIV slides the desc div from the top edge of the image ###*/
.imagepluscontainer div.upslide {
top: 0;
bottom: auto;
/* reset from default */
padding-bottom: 10px;
-moz-border-radius: 8px 8px 0 0;
-webkit-border-radius: 8px 8px 0 0;
border-radius: 8px 8px 0 0;
}
.imagepluscontainer:hover div.upslide {
-moz-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
-ms-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
transform: translate(0, -100%);
}
<div id="overlay"></div>
<div id="container">
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-1.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-2.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-3.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-4.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-5.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-6.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-1.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-2.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-3.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-4.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-5.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-6.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-1.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-2.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-3.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-4.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-5.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-6.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-1.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-2.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-3.jpg" alt="" class="photo-image" />
<div class="imagepluscontainer">
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-4.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-5.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
<div class="imagepluscontainer">
<div class="photo"><img src="http://s.cdpn.io/37045/wedding-6.jpg" alt="" class="photo-image" />
<div class="desc rightslide">Bdjfjffjkfjgjfgjfgjfgjfgjfjkg</div>
</div>
</div>
</div>
Here is the JSFiddle