function mycarousel_itemLoadCallback(carousel, state)
{
// Check if the requested items already exist
if (carousel.has(carousel.first, carousel.last)) {
return;
}
jQuery.get(
'dynamic_ajax_php.php',
{
first: carousel.first,
last: carousel.last
},
function(xml) {
mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
},
'xml'
);
};
function mycarousel_itemAddCallback(carousel, first, last, xml)
{
// Set the size of the carousel
carousel.size(parseInt(jQuery('total', xml).text()));
jQuery('image', xml).each(function(i) {
carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
});
};
/**
* Item html creation helper.
*/
function mycarousel_getItemHTML(url)
{
return '';
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
// Uncomment the following option if you want items
// which are outside the visible range to be removed
// from the DOM.
// Useful for carousels with MANY items.
// itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
itemLoadCallback: mycarousel_itemLoadCallback
});
});
Я хотел бы выполнить функцию сразу после того, как карусель завершила инициализацию и изображения оказались в dom и стали доступны. Однако это должно происходить только при загрузке страницы. Не каждый раз при нажатии предыдущей или следующей кнопки.
В качестве основы я использую базовый пример для jcarousel (карусель с динамической загрузкой контента через Ajax из PHP-скрипта): [code] function mycarousel_itemLoadCallback(carousel, state) { // Check if the requested items already exist if (carousel.has(carousel.first, carousel.last)) { return; }
function mycarousel_itemAddCallback(carousel, first, last, xml) { // Set the size of the carousel carousel.size(parseInt(jQuery('total', xml).text()));
jQuery('image', xml).each(function(i) { carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text())); }); };
/** * Item html creation helper. */ function mycarousel_getItemHTML(url) { return ''; };
jQuery(document).ready(function() { jQuery('#mycarousel').jcarousel({ // Uncomment the following option if you want items // which are outside the visible range to be removed // from the DOM. // Useful for carousels with MANY items.
// itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }}, itemLoadCallback: mycarousel_itemLoadCallback }); }); [/code] Я хотел бы выполнить функцию сразу после того, как карусель завершила инициализацию и изображения оказались в dom и стали доступны. Однако это должно происходить только при загрузке страницы. Не каждый раз при нажатии предыдущей или следующей кнопки.