简体   繁体   中英

Jquery - Scroll to bottom not working within bootstrap modal

I am doing a simple task of opening a bootstrap modal & there is a div within that modal with scrollbar & i am scrolling directly to the bottom.

Below is my code :-

<div id="ul_chats" style="height: 300px; overflow: auto;">
....
</div>

jq.ajax({
                url : "/Controller/GetComments",
                type : "get",
                dataType: "html",
                async: false,
                success : function(dataHtml) {                        
                    jq(".partialChats").html(dataHtml);
                    jq("#chatModal").modal('toggle');                             
                }                
            });

            var objDiv = document.getElementById("ul_chats");
            objDiv.scrollTop = objDiv.scrollHeight;

My Modal opens up but the div is not scrolled to the bottom. If i execute last 2 lines from the console then the div gets to the bottom.

Try a code like this

$("#ul_chats").animate({ scrollTop: $("#ul_chats").height() }, "slow");

if it does not work where you put the scroll, try to put it inside the sucess:

 success : function(dataHtml) {                        
                jq(".partialChats").html(dataHtml);
                jq("#chatModal").modal('toggle');
                $("#ul_chats").animate({ scrollTop: $("#ul_chats").height() }, "slow");         
            }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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