jquery-match-height icon indicating copy to clipboard operation
jquery-match-height copied to clipboard

Viewport jump despite _maintainScroll

Open Copylefter opened this issue 8 years ago • 4 comments

I have ajax load and this code.

In the main js file

 $(function() {
	 		$.fn.matchHeight._maintainScroll = true;
            $('.fragment-cell').matchHeight({
            	byRow: true
            });
            
 });

in particular js file for ajax.

Query(function($){

	$('.all-frag').append( '<span class="load-more">Загрузить ещё</span>' );
	$('.pagenav').remove();
	
	var button = $('.all-frag .load-more');
	var page = 2;
	var loading = false;
	
	// Get max number of pages
	var maxpage = beloadmore.maxpage;

	$('body').on('click', '.load-more', function(){
		if( ! loading ) {
			loading = true;
				var data = {
					action: 'be_ajax_load_more',
					page: page,
					query: beloadmore.query,
				};
				$(button).after('<span class="spinner-load"></span>')
					$('.load-more').remove()
					$.post(beloadmore.url, data, function(res) {
					
					if(res.success) {
						// Add and Fade in new articles
						$(res.data).hide().appendTo('.all-frag').fadeIn(500);
						$('.all-frag').imagesLoaded( function() {
						   console.log('all images loaded');
						  $(function() {
						   		$.fn.matchHeight._apply('.fragment-cell');
						            
						    });
						    
						});
					    $('.spinner-load').remove();
						if( page >= maxpage) {
							// If last page, remove "load more" button and replace with "No more articles" text.
							$('.load-more').remove();
							
						} else {
							$('.all-frag').append( button );
						}
						page = page + 1;
						loading = false;
				        
					} else {
						// console.log(res);
					}
				}).fail(function(xhr, textStatus, e) {
					// console.log(xhr.responseText);
				});
				
				}

	});
});

I have tried different variants, but this viewport jumping seems irremovable.

Copylefter avatar Feb 07 '17 11:02 Copylefter

Hi. I have the same behavior with ajax load. May be someone solved this problem?

robotE13 avatar Mar 31 '17 14:03 robotE13

I didn't.

Copylefter avatar Apr 10 '17 13:04 Copylefter

Unfortunately the maintain scroll feature isn't guaranteed to work in every situation, since I think the issue is very dependent on the circumstances of the page change and the browser / OS implementation of scrolling. For example in many cases it's ambiguous (i.e. contextual) where the scroll should be after given a page change and at what exact time the scroll needs to be rectified given things like animations. So it's often the case that a custom implementation will be needed.

liabru avatar Apr 10 '17 21:04 liabru

@robotE13 finaly I replaced it with css flex property

Copylefter avatar Apr 11 '17 15:04 Copylefter