滚动位置变得凌乱

时间:2015-05-29 05:12:45

标签: javascript jquery html css

我已经在textarea的keyup事件上创建了autoexpand textarea但是当它开始增长时,外部div滚动按下按键并上升。即使我在文本区域的按键上滚动(向下)底部(外部div滚动),它也会向上(向上)。我怎么能解决这个问题。

请参阅以下jsfiddle链接。

$("textarea").on("keyup", function($event) {
    $(".parent").scrollTop($(".parent").prop("scrollHeight"));
var textarea = $event.currentTarget;
            if (textarea.scrollHeight > 305) {
                textarea.style.height = "100px";
                textarea.style.height = (3+textarea.scrollHeight)+"px";
                $(textarea).css("overflow-y","scroll");
                //$(".scrollablePanel").scrollTop($(".scrollablePanel").prop("scrollHeight"));
            }
            else if (textarea.scrollHeight > 105){
                $(textarea).css("overflow-y","hidden");
                textarea.style.height = "100px";
                textarea.style.height = (3+textarea.scrollHeight)+"px";
                //$(".scrollablePanel").scrollTop($(".scrollablePanel").prop("scrollHeight"));
                $('.scrollablePanel').scrollTop($('.scrollablePanel').scrollTop() + 14);
            }
});

https://jsfiddle.net/ffzpa4qa/

0 个答案:

没有答案
相关问题