Speed up development with full-stack environments for every branch.

Learn More

How to create infinite scroll load with auto adjust content using jQuery

306 Runs 304 Views 75 Copies
Saved

Saved

dipesh.parmar 55

dipesh.parmar
published 4 years ago

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
	<title>Infinite Scroll Demo</title>
	<link rel="stylesheet" href="css/style.css" />
	<!-- scripts at bottom of page -->
</head>
<body class="demos">
	
	<section id="content">
		<h1>Infinite Scroll Demo</h1>
		
		<!--
			Main Container,
			with some static demo html
			You can replace it with sever-side scripts.
		-->
		<div id="container" class="transitions-enabled infinite-scroll clearfix">
			<div class="box col3">
				<p>
					<a href="http://www.flickr.com/photos/nemoorange/3318887645/" title="Clarendon Metro by nemoorange, on Flickr"><img src="http://farm4.static.flickr.com/3619/3318887645_1f33364338.jpg" alt="Clarendon Metro"  /></a>
				</p>
			</div>

			<div class="box col1">
				<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
			</div>
			<div class="box col2">
				<p>
					<a href="http://www.flickr.com/photos/nemoorange/3319714470/" title="Whitlow's on Wilson by nemoorange, on Flickr"><img src="http://farm4.static.flickr.com/3008/3319714470_c05a5cb5a8_m.jpg" alt="Whitlow's on Wilson" /></a>
				</p>
			</div>

			<div class="box col1">
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
			</div>

			<div class="box col1">
				<h2>Sit amet mi ullamcorper vehicula</h2>
			</div>

			<div class="box col1">
				<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p>
			</div>

			<div class="box col5">
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

				<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h2>

			</div>

			<div class="box col3">
				<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
				<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
				<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
				<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
			</div>

			<div class="box col2">
				<p>Sit amet mi ullamcorper vehicula</p>
			</div>

			<div class="box col1">
				<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
			</div>

			<div class="box col2">
				<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p>
				<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
			</div>

			<div class="box col3">
				<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
			</div>

			<div class="box col1">
				<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
			</div>

			<div>
				<div class="box col2">
					<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
					<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				</div>

				<div class="box col2">
					<p>Sit amet mi ullamcorper vehicula</p>
				</div>

				<div class="box col1">
					<p>Morbi purus libero</p>
				</div>

				<div class="box col1">
					<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
				</div>

				<div class="box col3">
					<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque felis.</p>
					<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
					<ul>
						<li>Lacus a ultrices sagittis</li>
						<li>Democratis</li>
						<li>Plummus</li>
					</ul>
				</div>

				<div class="box col1">
					<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				</div>
				<div class="box col1">
					<p>Sit amet mi ullamcorper vehicula</p>
				</div>

				<div class="box col1">
					<h2>Morbi purus libero</h2>
				</div>
				<div class="box col2">
					<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p>
					<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
				</div>
				<div class="box col1">
					<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula</p>
				</div>
				<div class="box col3">
					<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
					<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
					<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
				</div>
				<div class="box col1">
					<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p>
				</div>
				<div class="box col4">
					<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
					<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p>
					<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
				</div>
				<div class="box col2">
					<p>Sit amet mi ullamcorper vehicula</p>
				</div>
				<div class="box col1">
					<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
				</div>
				<div class="box col1">
					<h2>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </h2>
				</div>
				<div class="box col2">
					<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue.</p>
					<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p>
				</div>
				<div class="box col1">
					<ul>
						<li>Lacus a ultrices sagittis</li>
						<li>Democratis</li>
						<li>Plummus</li>
					</ul>
				</div>
				<div class="box col3">
					<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p>
					<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
					<p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus.</p>
				</div>

				<div class="box col2">
					<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p>
					<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue.  Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
				</div>
				<div class="box col1">
					<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
				</div>
				<div class="box col1">
					<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula</p>
				</div>
				<div class="box col3">
					<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
					<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p>
				</div>
			</div>

			<div class="box col1">
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
			</div>

			<div class="box col1">
				<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
			</div>

			<div class="box col1">
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
			</div>

			<div class="box col2">
				<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
			</div>

			<div class="box col1">
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
			</div>

			<div class="box col1">
				<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
			</div>
			<div class="box col1">
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
			</div>

			<div class="box col2">
				<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
			</div>
			<div class="box col1">
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
			</div>
			<div class="box col1">
				<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
			</div>
			<div class="box col1">
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
			</div>
			<div class="box col2">
				<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
			</div>
			<div class="box col1">
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p>
			</div>
			<div class="box col1">
				<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
			</div>
			<div class="box col1">
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
			</div>
			<div class="box col2">
				<p>Vestibulum volutpat, lacus a ultrices sagittis,</p>
				<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula  </p>
				<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p>
			</div>
		</div> <!-- #container -->
	
	<!--
		this is navigation section,
		which will be loaded when page is scrolled.
	-->
	<nav id="page-nav">
		<a href="page2.html"></a>
	</nav>

	<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" media="screen" />
	<script src="js/jquery-1.6.2.min.js"></script>
	<script src="js/jquery.masonry.min.js"></script>
	<script src="js/jquery.infinitescroll.min.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
	<script type="text/javascript">
		/*
			jQuery Document Ready
		*/
		$(function()
		{
			/*
				get container DOM into variable
			*/
			var $container = $('#container');
			
			/*
				Detect when images have been loaded
			*/
			$container.imagesLoaded(function()
			{
				/*
					initialize masonry
				*/
				$container.masonry
				({
					/*
						Specifies which child elements to be used as item elements.
						Setting itemSelector is always recommended.
					*/
					itemSelector: '.box',
					/*
						The width of a column of a horizontal grid
					*/
					columnWidth: 100
				});
			});
			
			// infinitescroll() is called on the element that surrounds
			// the items you will be loading more of
			$container.infinitescroll(
			{
				// selector for the paged navigation
				navSelector  : '#page-nav',
				// selector for the NEXT link (to page 2 then 3 etc)
				nextSelector : '#page-nav a',
				// selector for all items you'll retrieve
				itemSelector : '.box',
				// text accompanying loading image
                // default: "<em>Loading the next set of posts...</em>"
				loading:
				{
					finishedMsg: 'No more pages to load.',
					img: 'http://i.imgur.com/6RMhx.gif'
				}
			},
			// trigger Masonry as a callback
			function( newElements )
			{
				// hide new items while they are loading
				var $newElems = $( newElements ).css({ opacity: 0 });
				// ensure that images load before adding to masonry layout
				$newElems.imagesLoaded(function()
				{
					// show elems now they're ready
					$newElems.animate({ opacity: 1 });
					$container.masonry( 'appended', $newElems, true );
				});
			});
		});
	</script>

</section> <!-- #content -->

</body>
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).