简体   繁体   English

使悬停调整大小元素只影响元素

[英]Make hover resize element only affect the element

I have a list of elements that have a bit of information, and I want the user to be able to hover over an element to see more information. 我有一个包含一些信息的元素列表 ,我希望用户能够将鼠标悬停在元素上以查看更多信息。

However, doing something like: 但是,做一些事情:

$('a.song').each(function() {
  var origwidth = $(this).width();
  var origheight = $(this).height();
  $(this).hover(
    function() {
      $(this).stop().animate({width: origwidth * 2, height: origheight * 2});
    }, function() {
      $(this).stop().animate({width: origwidth, height: origheight});
  });
});

causes the element to affect the position of other elements (instead of simply overlapping), and the width expansion is limited by the column-count: 5; 导致元素影响其他元素的位置(而不是简单地重叠),宽度扩展受column-count: 5;限制column-count: 5; in the ol css rules. ol css规则中。

How can we make it so when the element expands it simply covers over any overlapping elements instead of pushing them, and properly expand the width even with column-count: 5; 当元素展开时,我们怎样才能做到这一点,它只是覆盖任何重叠元素而不是推动它们,并且即使column-count: 5;也适当地扩展宽度column-count: 5; ?

http://jsfiddle.net/Yk2du/1/ http://jsfiddle.net/Yk2du/1/

You could use position:absolute on the element and set the width of the container. 您可以在元素上使用position:absolute并设置容器的宽度。

In the jsfiddle I also used z-index to make sure the hovered element shows over the top of the others. 在jsfiddle中,我还使用了z-index来确保悬停元素显示在其他元素的顶部。

ol li {
  display: inline-block;
  margin: 5px 10px;
  position:relative;
  width: 200px;
  height: 40px;
}

ol li a {
  background-color: #EEE;
  display: block;
  width: 200px;
  height: 40px;
  cursor: pointer;
  text-overflow:ellipsis;
  overflow: hidden;
  white-space: nowrap;
  margin: 0;
    position:absolute;
}

PS You can do this with CSS3 and no javascript. PS你可以使用CSS3而不是javascript。

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

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