У меня есть изображения в слайд-div, которые я хотел бы центрировать. Функция "загружается" запускается после каждого слайда, есть ли способ запустить функцию один раз на всех изображениях?
// start jQuery Cycle
.cycle({
startingSlide: startSlide,
// when using the next/prev links
onPrevNextEvent: function(isNext, idx, slide) {
hasSlid = 1;
window.location.hash = (parseInt(idx) + 1) + "";
return false;
},
// when using the pager thumbnails
onPagerEvent: function(idx, slide) {
hasSlid = 1;
window.location.hash = (parseInt(idx) + 1) + "";
return false;
},
timeout: 0,
fx: 'scrollHorz',
next: '.cycle-next',
prev: '.cycle-prev',
speed: 200,
after: loaded,
});
function loaded(curr,next,opts) {
$('.slide .image img').each(function(){
var height = $(this).height();
var width = $(this).width();
$(this).css('margin-top','-' + height/2 +'px');
$(this).css('margin-left','-' + width/2 +'px');
$('img').animate({opacity:1},150)
});
};
Конечно, вызовите загруженный на загрузку страницы, а не цикл после события:
$('body').on('load', loaded);