我正在开发一个网页,其中用户可以通过将其悬停来显示较大图像或预览每个缩略图。将子类与父类垂直对齐
我正在使用此jquery代码来响应地在屏幕上显示和居中放大的图像。
var timer;
$(".theme-preview").hover(function() {
var self = $(this);
timer = setTimeout(function() {
timer = false;
$(self).children('.popup-preview').fadeIn("slow");
$(self).children('.popup-preview').css("position", "fixed");
$(self).children('.popup-preview').css("top", ($(window).height()/2) - ($(self).children('.popup-preview').outerHeight()/2));
$(self).children('.popup-preview').css("left", ($(window).width()/2) - ($(self).children('.popup-preview').outerWidth()/2));
}, 800);
//return false;
},
function() {
if (timer) {
clearTimeout(timer);
timer = false;
} else {
$(this).children('.popup-preview').fadeOut("fast");
}
//return false;
}
);
如何将垂直方向上的较大图像与父类对齐?
Here is my working sample code.
更新:实施例是当缩略图是在顶部或底部的屏幕,并徘徊。较大的图像应该垂直显示在屏幕中央。
这非常接近我想要达到的目标。但有一件事缺乏。例如,当缩略图位于屏幕的顶部或底部并被徘徊时。较大的图像应该垂直显示在屏幕中央。 https://jsfiddle.net/pbq5ujcp/44/ –
我会接受这个作为我的问题的答案,因为它是最接近我想实现的。我只需要添加'.css(“top”,($(window).height()/ 2) - ($(self).children('。popup-preview')。outerHeight()/ 2))'对于垂直居中见:https://jsfiddle.net/pbq5ujcp/45/ –
ohh ..我不知道你想基于高度居中。基于你的草图,它似乎是从顶部几个像素:) –