图像叠加层 "margin-top" 无法正确显示不同的图像高度
Image Overlay "margin-top" does not show correctly with differing image heights
问题在 fiddle JsFiddle
中最明显
图片叠加设置为margin-top:-100%;但它不适用于长度超过 300x300 的项目。
我试过使用 jquery 如下:
$(window).load(function () {
$(".overlay").each(function () {
var $parentHeight = $(".overlay").parent().height();
$(".overlay").css("margin-top", -$parentHeight);
});
});
结果相同。
你应该使用 top:0 而不是 margin-top:-100%;
.overlay {
width: 100%;
height: 100%;
background-color: red;
opacity: 0;
z-index: 1;
-webkit-transition: .2s all;
position: absolute;
top:0;
}
我对你的风格进行了修改,请看这里:https://jsfiddle.net/IA7medd/ngmpm5x0/
问题在 fiddle JsFiddle
中最明显图片叠加设置为margin-top:-100%;但它不适用于长度超过 300x300 的项目。
我试过使用 jquery 如下:
$(window).load(function () {
$(".overlay").each(function () {
var $parentHeight = $(".overlay").parent().height();
$(".overlay").css("margin-top", -$parentHeight);
});
});
结果相同。
你应该使用 top:0 而不是 margin-top:-100%;
.overlay {
width: 100%;
height: 100%;
background-color: red;
opacity: 0;
z-index: 1;
-webkit-transition: .2s all;
position: absolute;
top:0;
}
我对你的风格进行了修改,请看这里:https://jsfiddle.net/IA7medd/ngmpm5x0/