How to skip 10 steps in Bootstrap Tour?

丶灬走出姿态 提交于 2019-12-04 18:32:43

So, after reading DOCs - there is no method out-of-box to do skip steps.

But we can very easily build our own.


Simple solution (for exactly this scenario with 3 steps):

1.) add button role skip (our, new, role):

<button class='btn btn-xs btn-success' data-role='skip'>Skip</button>

2.) write method for skipping that catches skip button click:

$("body").on("click","button",function(){
    if($(this).attr("data-role") === 'skip'){
        alert("skip pressed :)");
        tour.goTo(2);        
    }
});

Less simple solution (for all scenarios):

1.) add buttons with role skip (our, new, role):

<button class='btn btn-xs btn-success' data-role='skip'>Skip</button>

...

<button class='btn btn-xs btn-success' data-role='skip'>Skip</button>

...

<button class='btn btn-xs btn-success' data-role='skip'>Skip</button>

...

etc

2.) have a method to: a.) find all steps b.) catch clicked button (skip) and it's step number (let's say x)) c.) goTo step x+1


Advanced solution:

extend Jquery plugin and add cross-scenario code to it

you can use this below code to achive this , For me its working

 onNext: function(tour){
  var curr=parseInt(tour.getState("current_step"));
  while(true){
    curr+=1;
    var step=tour.getStep(curr);
    //TODO: check if it's undefined
    if($(step.element).length){
      tour.goto(curr);
      return curr;
    }
  }
},
onPrevious: function(tour){
  var curr=parseInt(tour.getState("current_step"));
  while(true){
    curr-=1;
    var step=tour.getStep(curr);
    //TODO: check if it's undefined
    if($(step.element).length){
      tour.goto(curr);
      return curr;
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!