Lightbox no longer works after jQuery pagination is triggered (jQuery and lightbox conflict)
We are using two scripts at the same time: prettyPhoto and jQuery pagination. When the page first loads, both of the scripts are working. However, when I click on Page 2 of the pagination, the lightbox no longer shows but I can still go from one page to the next. These are the initialization scripts for both:
jQuery Pagination:
<script type="text/javascript">
// This is a very simple demo that shows how a range of elements can
// be paginated.
// The elements that will be displayed are in a hidden DIV and are
// cloned for display. The elements are static, there are no Ajax
// calls involved.
/**
* Callback function that displays the content.
*
* Gets called every time the user clicks on a pagination link.
*
* @param {int} page_index New Page index
* @param {jQuery} jq the container with the pagination links as a jQuery object
*/
function pageselectCallback(page_index, jq){
var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
$('#Searchresult').empty().append(new_content);
return false;
}
/**
* Initialisation function for pagination
*/
function initPagination() {
// count entries inside the hidden content
var num_entries = jQuery('#hiddenresult div.result').length;
// Create content inside pagination element
$("#Pagination").pagination(num_entries, {
callback: pageselectCallback,
items_per_page:1 // Show only o开发者_StackOverflow社区ne item per page
});
}
// When document is ready, initialize pagination
$(document).ready(function(){
initPagination();
});
</script>
prettyPhoto:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
Anyone knows where the conflict lies? Thanks.
I found a solution to my problem (which I found on another forum):
I just need to insert $("a[rel^='prettyPhoto']").prettyPhoto(); inside the function pageselectCallback like so:
function pageselectCallback(page_index, jq){
var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
$('#Searchresult').empty().append(new_content);
$("a[rel^='prettyPhoto']").prettyPhoto();
return false;
}
If I could only give +1 to the guy who answered it here. :)
try using Jquery .delegate()
$("a").delegate("[rel^='prettyPhoto']", "load", function()
{
$("a[rel^='prettyPhoto']").prettyPhoto();
});
精彩评论