2013-04-11 79 views
0

我真的被困在这一个...动态高度tinyscrollbar

我在div上使用tinyscrollbar.js插件。在该div里面,我有一个视口,其中包含一个段落和一个按钮,用于切换500px和1000px之间的段落高度。我如何动态更新tinyscrollbar以注意到新高度并自行更正? (请想象有其他九个“box_content review”div)

我尝试使用网站建议的tinyscrollbar_update方法,但它似乎不起作用。有人有想法吗?

感谢

HTML -

<div id="scrollbar3"> 
<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div> 
    <div class="viewport"> 
    <div class="overview"> 
    <div class="box_content review"> 
    <h5 class="reviewTitle">Review title: D90 is the best camera</h5> 
    <img src="../../images/gen_rating_5.png" /> 
    <div class="topCont"> 
    <img src="../../images/profile.png" /> 
    <p class="pros">Pros - LightWeight, Quality, Performance, Durable, Reliable </p> 
    <p class="cons">Cons - Expensive, Interchangable Parts </p> 
    </div> 
    <p class="reviewContent">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book... &nbsp <span><i><a class="readMore">read more</a></i></span></p> 
</div> 
</div> 
</div> 
</div> 

jQuery的 -

$('#scrollbar3').tinyscrollbar({ sizethumb: 45 }); 
    $(".readMore").toggle(function(){ 
     $(this).parent().parent().parent().animate({height:530},400); 
     $('#scrollbar3').tinyscrollbar_update(); 
    },function(){ 
     $(this).parent().parent().parent().animate({height:76},400); 
     $('#scrollbar3').tinyscrollbar_update(); 
    }); 
+0

请提供一些标记 – 2013-04-11 12:11:27

+0

只是一个想法,如果“tinyscrollbar_update” &&如果你正确地使用这一切,那么替代方法是让父元素克隆前,它初始化tinyscrollbar,然后resize函数,在父元素之后插入原始克隆的克隆,移除父元素,并在新插入的克隆上再次建立tinyscroll。或者使用jQuery的[replaceWith方法](http://api.jquery.com/replaceWith/) – SpYk3HH 2013-04-11 12:14:00

+0

为什么不在切换高度后重新初始化tinyscrollbar? – 2013-04-11 12:15:11

回答

1

好了,我到底做的是前手的内容添加和给父母的div一个溢出:隐藏并固定高度以“隐藏”内容。然后点击我将高度更改为“自动”。

1

更新tinyscrollbar时,动画尚未完成。动画完成后,使用complete callback function更新tinyscrollbar。

$(this).parent().parent().parent().animate(
    { height:530 }, 
    400, 
    function() { 
     $('#scrollbar3').tinyscrollbar_update(); 
    } 
); 
+0

这是有益的,谢谢! – 2013-08-29 08:52:45