Javascript 无法为Ajax加载销毁jQuery老虎机

Javascript 无法为Ajax加载销毁jQuery老虎机,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在使用jQuery老虎机插件()和Barbra.js()支持的Ajax加载,当加载带有jQuery老虎机的页面时,我很难销毁以前的实例并重新初始化jQuery老虎机 我的jQuery老虎机JS: function machine_1_init(){ //console.log('Start Machine 1'); const machine_1 = document.querySelector('#machine-1'); const slot_1 = new SlotMa

我正在使用jQuery老虎机插件()和Barbra.js()支持的Ajax加载,当加载带有jQuery老虎机的页面时,我很难销毁以前的实例并重新初始化jQuery老虎机

我的jQuery老虎机JS:

function machine_1_init(){

  //console.log('Start Machine 1');

  const machine_1 = document.querySelector('#machine-1');
  const slot_1 = new SlotMachine(machine_1, {
    randomize() {
      return this.nextIndex;
    }
  });

  function slot_1_run() {
    slot_1.shuffle(this.nextIndex);
  }

  jQuery(document).ready(function(){
      setTimeout(slot_1_run, 300);
  });

  jQuery( startBtn ).click(function() {
      slot_1_run()
  });

};

function machine_2_init(){
  //console.log('Start Machine 2');

    const machine_2 = document.querySelector('#machine-2');
    const slot_2 = new SlotMachine(machine_2, {
      randomize() {
        return this.nextIndex;
      }
    });

    function slot_2_run() {
      slot_2.shuffle(this.nextIndex);
    }

    jQuery(document).ready(function(){
        setTimeout(slot_2_run, 400);
    });


    jQuery( startBtn ).click(function() {
        setTimeout(slot_2_run, 300);

    });

};

 jQuery(document).ready(function(){
    machine_1_init();
    machine_2_init();
});
然后是Barbra JS的东西:

// Barba

barba.init({
  transitions: [{
    name: 'opacity-transition',
    leave(data) {
      return gsap.to(data.current.container, {
        opacity: 0
      });
    },
    enter(data) {
      return gsap.from(data.next.container, {
        opacity: 0
      });
    }
  }],

  views: [{
   namespace: 'home-page',
   beforeEnter() {},
   afterEnter() {

   },
 }]

});

barba.hooks.enter(() => {
  window.scrollTo(0, 0);
});

barba.hooks.beforeEnter(() => {
  console.log('destroy_1');
  console.log('destroy_2');
  slot_1.destroy();
  slot_2.destroy();
});


barba.hooks.afterEnter(() => {
  reInit();
});

最后,reInit函数:

function reInit() {
  machine_1_init();
  machine_2_init();

  var loadVid2 = jQuery('.video-js');
  for(var i = 0; i < loadVid2.length; i++){
    videojs(loadVid2[i]).ready(function(){});
    console.log('Second Video Load.');
  }

  var ytloadVid2 =  jQuery('.vjs-youtube');
  for(var i = 0; i < ytloadVid2.length; i++){
    videojs(ytloadVid2[i]).ready(function(){});
    console.log('Second YT Video Load.');
  }


  destroyCarousel()
  jQuery('.slider').each(function(){
      initializeBlock(  jQuery(this) );
      //console.log('Slider Rebuild');
  });

  jQuery('.home-slider').each(function(){
      initializeBlock(  jQuery(this) );
      //console.log('Slider Rebuild');
  });

  jQuery('.slideshow').each(function(){
      initializeBlock(  jQuery(this) );
      //console.log('Slideshow Rebuild');
  });

};
函数reInit(){
机器_1_init();
机器_2_init();
var loadVid2=jQuery('.video js');
对于(变量i=0;i
我已经在上查看了jQuery老虎机文档,并尝试了Slot_1.destroy();并销毁(插槽_1);没有运气