matt136 matt136 - 11 months ago 45
HTML Question

jQuery Slide Down - Sliding from Top-Left for Image

I have some jQuery for an image overlay which should slide down on hover using the

function. The issue is that it doesn't slide down from the top but grows from the top-left. Please see it here:

My code is below. Could anybody please advise what I am doing wrong with the
function for it to be doing this? Thank you for your help.

HTML & jQuery:

jQuery(document).ready(function() {
jQuery(".imageslide").mouseenter(function() {
jQuery(".overlayimage").slideDown(200, "linear");
jQuery(".imageslide").mouseleave(function() {
jQuery(".overlayimage").slideUp(200, "linear");

<div class="imageslide">
<img class="normalimage" style="position: absolute" src="">
<img class="overlayimage" style="position: absolute" src="">


/* Image Overlay Slide Down (Start) */
.normalimage {
cursor: pointer;

.overlayimage {
cursor: pointer;
display: none;
/* Image Overlay Slide Down (End) */

Answer Source

.sideDown() simply animates the height of the object. Since the image has no width, the width is animating with the height in order to maintain aspect ratio. You can resolve the expansion of the image by giving the .overlayimage a width: 100% style. Unfortunately, this will break the aspect ratio of the image and will cause it to stretch so you will need to take a different approach in order to get the effect you are looking for.