我只想在之前的自定义功能完全完成后才执行自定义功能。
我尝试了承诺,完成以及何时,但它无法正常工作。执行第二个函数时,第一个函数没有完全完成......
例如,我想执行 function1() 然后仅在 function1 完成时执行 function2 :
function1();
function2();
我试过了,但它根本不起作用:
promise(function1()).done(function2);
这是我的 function1 的脚本:
function function1() {
nbofslides = $('.Slide img').length;
currentslide = 1;
if ( nbofslides == currentslide) {
if ( nbofslides > 1) {
for (i = 1 ; i <= nbofslides ; i++) {
if (i == 1) {
$('.slider-pagination').append('<li class="slider-page selected bgcolor2"></li>');
} else {
$('.slider-pagination').append('<li class="slider-page bgcolor2"></li>');
}
}
}
$('.iosSlider').iosSlider({
responsiveSlideContainer: true,
responsiveSlides: true,
snapToChildren: true,
desktopClickDrag: true,
keyboardControls: true,
infiniteSlider: true,
navSlideSelector: true,
autoSlide: false,
navNextSelector: $('.slider-next'),
navPrevSelector: $('.slider-prev'),
navSlideSelector: $('.slider-pagination .slider-page'),
onSlideChange: slideChange
});
var setHeight = $('.iosSlider .Slide:eq(0)').outerHeight(true);
$('.iosSlider').css({
height: setHeight
});
function slideChange(args) {
$('.slider-pagination .slider-page').removeClass('selected');
$('.slider-pagination .slider-page:eq(' + (args.currentSlideNumber - 1) + ')').addClass('selected');
}
}
currentslide++;
}