工作原型:http: //jsfiddle.net/ad5qa/K5fdZ/28/
出于某种原因,当单击更多按钮时,parentsUntil 正在抓取页面中的所有 div。我只想获取 div.htmlbox 并自动设置高度,这样我就可以看到全部内容。然后单击 less 将其缩小到 50px 高度。任何帮助将不胜感激。
$('.morebox a').toggle(function() {
var $this = $(this);
var $parent =$this.parentsUntil('.htmlbox');
$parent.height('auto')
$this.text('less')
$parent.css('border', '2px solid magenta')
$this.css('border', '2px solid red')
}, function() {
$parent.height('50px')
$this.text('more')
});
<h3>Description</h3>
<div class="htmlbox">
This is a samle description that goes here with short or long content in this panel. If the text is higher than 50px then it should be hidden by the box. You must click expand to view the remaining content in the html box div. The float box is used to cut off the overflow of the content.
<div class="fade-overlay"></div>
</div>
<div class="morebox">
<img align="absmiddle" alt="more-less grabber" src="http://goo.gl/ho277">
<a href="#" style="line-height: 10px">more</a>
<img align="absmiddle" alt="more-less grabber" src="http://goo.gl/ho277">
</div>