Why my Php/Jquery script causes the images to overlap?
I'm using jQuery Infinite Scroll Pagination in conjunction with masonry to position each element in the next open spot in the grid
, and within this script i have a (while loop) that fetches records from the database, everything seems to be working properly until i start to scroll down then something goes wrong and causes item elements to overlap showing the images overlapping one another.
I tried solutions like Imagesloaded but i had no luck.
Kindly check out my code below and tell me what goes wrong.
Thank you for your help.
Here is my code.
- <?php
- $limit = 10;
- $page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
- $sql = "SELECT * FROM `table` ORDER BY `img_id` DESC";
- $start = ($page * $limit) - $limit;
- if( mysql_num_rows(mysql_query($sql)) > ($page * $limit) ){
- $next = ++$page;
- }
- $query = mysql_query( $sql . " LIMIT {$start}, {$limit}");
- if (mysql_num_rows($query) < 1) {
- header('HTTP/1.0 404 Not Found');
- echo 'Page not found!';
- exit();
- }
- ?>
- <html>
- <head>
- <title>Page Title</title>
- <link rel="stylesheet" href="path/to/style.css">
- </head>
- <body>
- <div id="container">
- <?php while ($row = mysql_fetch_array($query)): ?>
- <div class="item item-<?php echo $row['img_id']?>">
- <?php
- $image_file = 'path/to/images/files.extension';
- echo '<img src="'.$image_file.'" />';
- ?>
- </div>
-
- <?php endwhile?>
- <?php if (isset($next)): ?>
- <div class="nav">
- <a href='thisPage.php?p=<?php echo $next?>'>Next</a>
- </div>
- <?php endif?>
- </div>
-
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
- <script type="text/javascript" src="path/to/jquery-ias.min.js"></script>
- <script type="text/javascript" src="path/to/masonry.pkgd.js"></script>
-
- <script type="text/javascript">
- $(document).ready(function(){
- var $container = $('#container');
- $container.masonry({
- filter: '*',
- animationOptions: {
- duration: 750,
- easing: 'linear',
- queue: false,
- }
- });
-
- $(document).ready(function() {
- jQuery.ias({
- container : '#container',
- item: '.item',
- pagination: '.nav',
- next: '.nav a',
- loader: 'Loading More Items. . .',
- triggerPageThreshold: 3
- });
- });
- });
- </script>
- </body>
- </html>