Controlling page scrolling by jquery add data

I have a page with certain images and I am showing about 20 pictures which are 20 times vertically one after the other. after those 20, i have a div, show more. by clicking the Show More button, I will load 20 more and add to the first dataset, a typical solution we find on many websites, such as loading more data only when the user clicks the Show More / Load More button ".

everything works fine for me, except that when I add the next set of data pages it doesn't stay stationary, its scroll becomes awkward and moves to the start of the first div or near.

My question is, how do we handle scrolling in this case?

+3


source to share


2 answers


You need element.scrollIntoView();

in javascript



Or, jquery scrollto

+2


source


Unfortunately, it's hard to tell without some code, but it looks like you haven't prevented the link's default action:



$("#show-more-link").click(function(e) {
   e.preventDefault();
   addMoreImages();
}

      

+3


source







All Articles