简体   繁体   English

jQuery向下滑动-从左上滑动图像

[英]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 slideDown function. 我有一些用于图像叠加层的jQuery,应该使用slideDown函数在悬停时向下滑动。 The issue is that it doesn't slide down from the top but grows from the top-left. 问题是它不会从顶部滑落,而是从左上方生长。 Please see it here: 请在这里查看:

http://ts564737-container.zoeysite.com/ http://ts564737-container.zoeysite.com/

My code is below. 我的代码如下。 Could anybody please advise what I am doing wrong with the slideDown function for it to be doing this? 有人可以告诉我我使用slideDown函数做错了什么吗? Thank you for your help. 谢谢您的帮助。

HTML & jQuery: HTML和jQuery:

<script>
    jQuery(document).ready(function() {
        jQuery(".imageslide").mouseenter(function() {
            jQuery(".overlayimage").slideDown(200, "linear");
        });
        jQuery(".imageslide").mouseleave(function() {
            jQuery(".overlayimage").slideUp(200, "linear");
        });
    });
</script>

<div class="imageslide">
    <img class="normalimage" style="position: absolute" src="https://s3.amazonaws.com/zcom-media/sites/a0iE000000MFs6GIAT/media/mediamanager/menslookup_1.png">
    <img class="overlayimage" style="position: absolute" src="https://s3.amazonaws.com/zcom-media/sites/a0iE000000MFs6GIAT/media/mediamanager/menslookup_2.png">
</div>

CSS: CSS:

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

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

.sideDown() simply animates the height of the object. .sideDown()只是将对象的高度设置为动画。 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. 您可以通过给.overlayimage设置width: 100%样式来解决图像的扩展。 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. 不幸的是,这会破坏图像的长宽比并导致其拉伸,因此您需要采取其他方法才能获得所需的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM