0

一个 div 容器很好地打开以适应溢出内容。有用。但是如何将触发的 HTML 元素的引用与 jQuery 连接起来。应该有比这更好的方法$("#"+divId)

我得到了这个代码:

$('.text').mouseenter(function() {

//var $id = $(this); ?
//var $id = document.getElementById(divId); ?
var divId = this.id;
    var $id = $("#"+divId);

var overflow = $id.prop("scrollHeight");

this.divHeight = $id.height();

$id.animate({height:overflow},1000);
});

.text{
color: #000000;
background-color: #ffffff;
overflow: hidden;
height: 100px;
position: relativ;}


<div  class="text" id="text1">
<content>
</div>
<div  class="text" id="text2">
<content>
</div>
<div  class="text" id="text3">
<content>
</div>

PS为什么$(this).height()有效,但不是$(this).prop("scrollHeight")

感谢帮助理解。

4

2 回答 2

2

尝试这样的事情

改变这个

var divId = this.id;
var $id = $("#"+divId);

var $id = $(this);
于 2013-10-07T11:52:43.770 回答
0
   Use jquery method like this
    $(this).prop("scrollHeight");
于 2013-10-07T11:56:22.203 回答