I'm using jQuery Infinite-Scroll plugin for a masonry gallery. Masonry gallery working without any issue. But infinite scroll loads next page before reaching the bottom.also loading image not showing always.
index.php
<?php
$con = mysqli_connect('localhost','root','root','database');
$per_page = 10;
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else {
$page=1;
}
$start_from = ($page-1) * $per_page;
$query = "SELECT * FROM data ORDER BY rand() LIMIT $start_from, $per_page";
$result = mysqli_query ($con, $query);
while ($row = mysqli_fetch_array($result)) {
?>
<div id="gallery">
<ul id ="container" class="transitions-enabled infinite-scroll clearfix">
<li class="item">item 1</li>
<li class="item">item 2</li>
<li class="item">item 3</li>
</ul>
<?php } ?>
<nav id="page-nav">
</nav>
</div>
I think this issue related to this PHP codes because jQuery script codes are working without any issue. somehow this php codes loading 10 images for next page from database. Please can I have a good PHP code for infinite scroll more than this?
script.js
$(function(){
var $container = $('#container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.item',
columnWidth: 100
});
});
// infinite scroll options...
$container.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector : '.item', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// trigger Masonry as a callback
function( newElements ) {
var $newElems = $( newElements ).css({ opacity: 0 });
$newElems.imagesLoaded(function(){
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}
);
});
Related
My code is work fine.. but I like save the order in Mysql of the second column as soon as I make any changes... The PHP programming I can do, just do not know how to send the changes to php file
See my code ( complete code in: http://jsfiddle.net/helpinspireme/wMnsa/ )
<ul id="unassigned_list" class="connected_sortable">
<li class="ui-state-default"><div class="draggable_area">Item 1</div><div class="click_area">→</div><div class="cl"></div></li>
<li class="ui-state-default"><div class="draggable_area">Item 2</div><div class="click_area">→</div><div class="cl"></div></li>
</ul>
<ul id="recipients_list" class="connected_sortable">
<li class="ui-state-highlight"><div class="draggable_area">Item 3</div><div class="click_area">←</div><div class="cl"></div></li>
<li class="ui-state-highlight"><div class="draggable_area">Item 4</div><div class="click_area">←</div><div class="cl"></div></li>
</ul>
<script>
$("#unassigned_list, #recipients_list").sortable({
connectWith: ".connected_sortable",
items: "li",
handle: ".draggable_area",
stop: function(event, ui) {
updateLi(ui.item);
}
}).disableSelection().on("click", ".click_area", function() {
// First figure out which list the clicked element is NOT in...
var otherUL = $("#unassigned_list, #recipients_list").not($(this).closest("ul"));
var li = $(this).closest("li");
// Move the li to the other list. prependTo() can also be used instead of appendTo().
li.detach().appendTo(otherUL);
// Finally, switch the class on the li, and change the arrow's direction.
updateLi(li);
});
function updateLi(li) {
var clickArea = li.find(".click_area");
if (li.closest("ul").is("#recipients_list")) {
li.removeClass("ui-state-default").addClass("ui-state-highlight");
clickArea.html('←');
} else {
li.removeClass("ui-state-highlight").addClass("ui-state-default");
clickArea.html('→');
}
}
</script>
You can do it by adding id to elements and adding code below to sortable:
update: function() {
var order = $(this).sortable('toArray');
alert(order);
}
Online demo (jsFiddle)
I am using Isotope with a masonry layout in WordPress, along with ImagesLoaded. Each post is a separate isotope item. All seems to be working well, except when I load something dynamic in the post, like a twitter widget or a embedded video. The initial height of the item is set before the post/widget has loaded. Once it has fully loaded, I need isotope to re-layout again to accommodate the new height.
Is there a way to call the layout function again after all the posts are fully loaded?
Here is my isotope code:
// init isotope
var $container = $('#cards');
$container.isotope({
itemSelector: '.item',
masonry: {
columnWidth: '.grid-sizer',
isFitWidth: true
}
});
// layout Isotope again after all images have loaded
$container.imagesLoaded( function() {
$container.isotope('layout');
});
// infinite scroll
$container.infinitescroll({
navSelector : '.pagination',
nextSelector : '.pagination a',
itemSelector : '.item-scroll',
behavior: "twitter",
loading: {
finishedMsg: 'No more pages to load.'
}
},
function ( newElements ) {
var $newElems = jQuery( newElements ).hide(); // hide to begin with
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
$newElems.fadeIn(); // fade in when ready
$container.isotope( 'appended', $newElems );
});
}
);
function onLayout() {
$container.infinitescroll('scroll');
}
Thank you for your help!
Try this:
var $container = $('#cards');
$container.imagesLoaded( function() {
// init isotope
$container.isotope({
itemSelector: '.item',
masonry: {
columnWidth: '.grid-sizer',
isFitWidth: true
}
});
});
// infinite scroll
$container.infinitescroll({
navSelector : '.pagination',
nextSelector : '.pagination a',
itemSelector : '.item-scroll',
behavior: "twitter",
loading: {
finishedMsg: 'No more pages to load.'
}
},
function ( newElements ) {
var $newElems = jQuery( newElements ).hide(); // hide to begin with
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
$newElems.fadeIn(); // fade in when ready
$container.isotope( 'appended', $newElems ).isotope('layout');
});
}
);
function onLayout() {
$container.infinitescroll('scroll');
}
Please have a look at http://iglica.dbox.pl/modx/ (clients graphical project)
Check "KURSY" on the menu - on the homepage everything is okay, the menu slides, I can pick something from the sub-menu, etc. Somehow, when I click on "KURSY" from every other place, MODX redirects me to the homepage.
The code responsible for the menu is in menu.min.js (I`ve bought it specially for this website - I'm not a jQuery familiar).
P.S.
I've tried this http://rtfm.modx.com/display/revolution20/Named+Anchor with no luck
P.S.
jQuery -
$(function () {
$('#mainNav ul li.slide a').click(function () {
var content = ($(this).parent().find("div").html());
$('#navWrapper #subNav #subNavContainer').fadeOut(100, function () {
$('#navWrapper #subNav #subNavContainer').html(content);
$('#navWrapper #subNav #subNavContainer').fadeIn(100);
$('#navWrapper').stop(false, false).animate({
'left': 0
}, 300)
})
});
$('#navWrapper').mouseleave(function () {
$('#navWrapper').stop(false, false).animate({
'left': -200
}, 300)
})
});
Try to replace the a tags which you don't want to do anything with span tags and see if your js code still works fine. Maybe you have to look at your css styles afterwards.
<li class="slide"><span>Kursy</span>
<div class="submenu">
<ul id="submenu">
<li>Dla dzieci</li>
<li>Dla młodzieży</li>
<li>Dla dorosłych</li>
</ul>
</div>
</li>
Ok, when slide functions are triggered by anchor may try a js workaround:
HTML
<li class="slide">Kursy
<div class="submenu">
<ul id="submenu">
<li>Dla dzieci</li>
<li>Dla młodzieży</li>
<li>Dla dorosłych</li>
</ul>
</div>
</li>
JS
(function ($) {
$(window).ready(function () {
$('.preventdefault').on("click", function (e) {
//Uncomment if the anchor is required on the url
//document.location.hash = $(this).attr('href');
return false;
});
});
}(jQuery));
Your code extended + adding html class:
$(function () {
$('#mainNav ul li.slide a').click(function (e) {
var content = ($(this).parent().find("div").html());
$('#navWrapper #subNav #subNavContainer').fadeOut(100, function () {
$('#navWrapper #subNav #subNavContainer').html(content);
$('#navWrapper #subNav #subNavContainer').fadeIn(100);
$('#navWrapper').stop(false, false).animate({
'left': 0
}, 300)
})
if ($(this).hasClass('preventdefault')) {
//Uncomment if the anchor is required on the url
//document.location.hash = $(this).attr('href');
e.preventDefault();
e.stopPropagation();
}
});
$('#navWrapper').mouseleave(function () {
$('#navWrapper').stop(false, false).animate({
'left': -200
}, 300)
})
});
I'm using infinite scroll with dynamic data but can't seem to get past page 2...
When the page initially loads I have an offset in the URL so we start at 0, so,
test2.html?offset=0
this is the code to load the date
$offset = $_GET['offset'];
$data = mysql_query("select * from list limit 30 offset $offset;",$db);
echo '<div id="wall" class="transitions-enabled infinite-scroll clearfix">';
while ($databack33 = mysql_fetch_array($data)){
echo '<div class="block">';
echo '';
echo '</div>';
}
Then to load the next page i use:
<nav id="page-nav">
<? $offset = $offset+30; ?>
</nav>
This works ok for pages one and two but it then tells me no more pages to load although there is more data.
If I look at the page source it is correct test2.html?offset=60
this is the masonry/infinite scroll set up
<script type="text/javascript">
$(function(){
var $container = $('#wall');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.block',
isAnimated: true,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
});
$container.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector : '.block', // selector for all items you'll retrieve
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>
To get infinitescroll working with "offset=" pagination I did the following:
Store the current 'next page' url, and get the offset value.
var nextSelector = '#page-nav a';
var origNextUrl = $(nextSelector).attr('href');
var offsetRegex = /(offset=)([0-9]+)/;
var offset = origNextUrl.match(offsetRegex)[2];
Then in infinitescroll assign a function to the 'path' option which accepts a page number and returns the url used to load the next page.
$container.infinitescroll({
// other options
path: function(pageNum) {
return origNextUrl.replace( offsetRegex, ("$1" + (offset * pageNum)) );
},
//callback
});
I am still trying to figure out how to fix my pagination script to work properly.
the problem I am having is when I click any of the pagination number links to go the next page, the new content does not load. literally nothing happens and when looking at the console in Firebug, nothing is sent or loaded.
I have on the main page 3 links to filter the content and display it. When any of these links are clicked the results are loaded and displayed along with the associated pagination numbers for that specific content.
I believe the problem is coming from the function(generate_pagination.php (seen below)).
Here is the main page so you can how I am including and starting the function(I'm new to php):
<?php
include_once('generate_pagination.php');
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>
<div id="loading" ></div>
<div id="content" data-page="1"></div>
<ul id="pagination">
<?php generate_pagination($sql) ?>
</ul>
<br />
<br />
Marketing
Automotive
Sports
This is as mentioned above, where i think the problem persists since I know nothing of the function formats and how to properly incorporate them:
<?php
function generate_pagination($sql) {
include_once('config.php');
$per_page = 3;
//Calculating no of pages
$result = mysql_query($sql);
$count = mysql_fetch_row($result);
$pages = ceil($count[0]/$per_page);
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
}
$ids=$_GET['ids'];
generate_pagination("SELECT COUNT(*) FROM explore WHERE category='$ids'");
?>
I thought I might as well through in the jquery if someone wants to see:
$(document).ready(function(){
//Display Loading Image
function Display_Load()
{
$("#loading").fadeIn(900,0);
$("#loading").html("<img src='bigLoader.gif' />");
}
//Hide Loading Image
function Hide_Load()
{
$("#loading").fadeOut('slow');
};
//Default Starting Page Results
$("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});
Display_Load();
$("#content").load("pagination_data.php?page=1", Hide_Load());
//Pagination Click
$("#pagination li").click(function(){
Display_Load();
//CSS Styles
$("#pagination li")
.css({'border' : 'solid #dddddd 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
//Loading Data
var pageNum = this.id;
$("#content").load("pagination_data.php?page=" + pageNum, function(){
$(this).attr('data-page', pageNum);
Hide_Load();
});
});
// Editing below.
// Sort content Marketing
$("a.category").click(function() {
Display_Load();
var this_id = $(this).attr('id');
$.get("pagination.php", { category: this.id },
function(data){
//Load your results into the page
var pageNum = $('#content').attr('data-page');
$("#pagination").load('generate_pagination.php?category=' + pageNum +'&ids='+ this_id );
$("#content").load("filter_marketing.php?page=" + pageNum +'&id='+ this_id, Hide_Load());
});
});
});
Any help would be appreciated on getting the function to work properly. Thank you
IDs cannot start with numbers, give your IDs another starting string like page, like this:
In php:
for($i=1; $i<=$pages; $i++)
{
echo '<li class="page_numbers" id="page'.$i.'">'.$i.'</li>';
}
In jQuery:
var pageNum = $(this).attr("id").replace("page","");
$("#content").load("pagination_data.php?page=" + pageNum, function(){
$(this).attr('data-page', pageNum);
Hide_Load();
});
That should at least start posting back something, please comment if it doesn't.