简体   繁体   English

滚动Div随着增加高度

[英]Scroll Div With increase height

$(".clickable").each(function(idx, elem) { // register click for slides
    elem = $(elem);
    elem.click(function() {
       scaleClicked(elem); 
    });
});

function scaleClicked(elem) { // slide clicked
     var id = elem.attr("id"),
         num = id.slice(-1),
         postId = "post"+num,
         posts = $(".post");
    posts.each(function(idx, p) {
        if($(p).attr("id") == postId) { 
            scaleUp(p);
        }
        else {
             scaleDown(p);   
        }
    });

}

function scaleUp(item) {
    $(item).animate({height:1000},1000);
}
function scaleDown(item) {
    $(item).animate({height:30},1000);
}

I need to Increase div height on click, like example 01 and at the same time, That Div Must scroll to Top of the window Like Example 02 . 我需要增加单击时的div高度,例如示例01 ,同时,该Div必须像示例02一样滚动到窗口顶部。 Can You Help With This. 您能帮上忙吗?

i tried few ways but when div increase the height, but it is scrolling to beyond the top level. 我尝试了几种方法,但当div增加高度时,却滚动到了顶层以上。 but i need to stop div,when it scroll to top level of the window. 但是当它滚动到窗口的顶层时,我需要停止div。

Instead of using an anchor to scroll like the example you gave you can scroll like this, for example to scroll to the bottom of a div: 不用像您给出的示例那样使用锚滚动,您可以像这样滚动,例如滚动到div的底部:

$("#mydiv").animate({ scrollTop: $('#mydiv')[0].scrollHeight}, 1000);

To scroll to an item in the div you can find the position to scroll to in a number of ways, there's a good discussion here: 要滚动到div中的某个项目,您可以通过多种方式找到要滚动到的位置,这里有一个很好的讨论:

How do I scroll to an element within an overflowed Div? 如何滚动到溢出的Div中的元素?

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

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