JQuery从中心收缩div
我已经创建了一些JQuery,它将在悬停时展开一个div“popup”,然后在鼠标悬停时缩小它。然而,这种效果似乎发生在左上角,我需要它发生在中间。我也看到过类似的关于堆栈溢出的主题,解决方案似乎是在JQuery和CSS中获得正确的“top”和“left”值,然而,尽管我尽了最大努力,我还是无法做到这一点 下面是我迄今为止所取得的工作成果的JS小提琴: 以下是无法访问JS Fiddle的用户的代码。JQuery从中心收缩div,jquery,css,shrink,Jquery,Css,Shrink,我已经创建了一些JQuery,它将在悬停时展开一个div“popup”,然后在鼠标悬停时缩小它。然而,这种效果似乎发生在左上角,我需要它发生在中间。我也看到过类似的关于堆栈溢出的主题,解决方案似乎是在JQuery和CSS中获得正确的“top”和“left”值,然而,尽管我尽了最大努力,我还是无法做到这一点 下面是我迄今为止所取得的工作成果的JS小提琴: 以下是无法访问JS Fiddle的用户的代码。 HTML JQuery: $(document).ready(function() { $
HTML JQuery:
$(document).ready(function() {
$('.productborder', this).hover(
function() {
$('.popup', this).stop(true, true);
$('.popup', this).animate({
width: '100px',
height: '100px',
top: '25px',
left: '55px'
}, 500);
}, function() {
$('.popup', this).animate({
width: '0px',
height: '0px',
top: '0px',
left: '0px'
}, 500);
});
});
在设置打开动画之前,将左/顶部设置为正确的“中心”位置,即
$(document).ready(function() {
$('.productborder', this).hover(
function() {
$('.popup', this).stop(true, true);
$('.popup', this).css({
left: '110px',
top: '75px'
});
$('.popup', this).animate({
width: '100px',
height: '100px',
top: '25px',
left: '55px'
}, 500);
}, function() {
$('.popup', this).animate({
width: '0px',
height: '0px',
top: '110px',
left: '75px'
}, 500);
});
});
$(document).ready(function() {
$('.productborder', this).hover(
function() {
$('.popup', this).stop(true, true);
$('.popup', this).animate({
width: '100px',
height: '100px',
top: '25px',
left: '55px'
}, 500);
}, function() {
$('.popup', this).animate({
width: '0px',
height: '0px',
top: '0px',
left: '0px'
}, 500);
});
});
$(document).ready(function() {
$('.productborder', this).hover(
function() {
$('.popup', this).stop(true, true);
$('.popup', this).css({
left: '110px',
top: '75px'
});
$('.popup', this).animate({
width: '100px',
height: '100px',
top: '25px',
left: '55px'
}, 500);
}, function() {
$('.popup', this).animate({
width: '0px',
height: '0px',
top: '110px',
left: '75px'
}, 500);
});
});