Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery从中心收缩div_Jquery_Css_Shrink - Fatal编程技术网

JQuery从中心收缩div

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

我已经创建了一些JQuery,它将在悬停时展开一个div“popup”,然后在鼠标悬停时缩小它。然而,这种效果似乎发生在左上角,我需要它发生在中间。我也看到过类似的关于堆栈溢出的主题,解决方案似乎是在JQuery和CSS中获得正确的“top”和“left”值,然而,尽管我尽了最大努力,我还是无法做到这一点

下面是我迄今为止所取得的工作成果的JS小提琴:

以下是无法访问JS Fiddle的用户的代码。
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);
    });

});​