Intro.js不能两个步骤之间的防火功能(请查看我的代码)(Intro.js not able t

2019-09-28 15:20发布

我绝对初学者用JS,请检查我的代码,我不能叫intro.js的两个步骤之间的函数。 现在我只是想显示警报,但失败了。

<script type="text/javascript">
var introguide = introJs();
$(function(){



introguide.setOptions({
steps: [
{
  element: '#chaman',
  intro: 'This is step1',
  position: 'top',
  onchange: function(){
    //do something interesting here...

    alert("Want to call function after this step , no alert showing ");
  },
  onbeforechange: function(){

  }
},
{
  element: '#search',
  intro: 'This is step 2.',
  position: 'bottom',
  onchange: function(){
    //do something interesting here...


  },
  onbeforechange: function(){

  }

}
,
{
  element: '.flyMarker',
  intro: 'This is step 3.',
  position: 'bottom',
  onchange: function(){
    //do something interesting here...
  },
  onbeforechange: function(){
    //do something else interesting here...
  }
}
]
});



setTimeout(function() { introguide.start(); }, 3000);


});


createStepEvents: function( guideObject, eventList ){

//underscore loop used here, foreach would work just as well
_.each( eventList, function( event ){

//for the guid object's <event> attribute...
guideObject[event]( function(){

  //get its steps and current step value
  var steps       = this._options.steps,
      currentStep = this._currentStep;

  //if it's a function, execute the specified <event> type
  if( _.isFunction(steps[currentStep][event]) ){
    steps[currentStep][event]();
  }
});

}, this );
}

//setup the events per step you care about for this guide
createStepEvents( introguide, ['onchange','onbeforechange']);



</script>

我想每一个步骤之后触发一些功能。

Answer 1:

不要忘记添加underscore.js 。

在你的代码的错误是:

createStepEvents: function( guideObject, eventList ){

改成:

function createStepEvents(guideObject, eventList) {

 var introguide = introJs(); $(function() { introguide.setOptions({ steps: [{ element: '#chaman', intro: 'This is step1', position: 'top', onchange: function() { alert("Do whatever you want on this callback."); }, onbeforechange: function() { } }, { element: '#search', intro: 'This is step 2.', position: 'bottom', onchange: function() { }, onbeforechange: function() { } }, { element: '.flyMarker', intro: 'This is step 3.', position: 'bottom', onchange: function() { }, onbeforechange: function() { } } ] }); setTimeout(function() { introguide.start(); }, 3000); }); function createStepEvents(guideObject, eventList) { //underscore loop used here. _.each(eventList, function(event) { //for the guid object's <event> attribute. guideObject[event](function() { //get its steps and current step value var steps = this._options.steps, currentStep = this._currentStep; //if it's a function, execute the specified <event> type if (_.isFunction(steps[currentStep][event])) { steps[currentStep][event](); } }); }, this); } //setup the events per step you care about for this guide createStepEvents(introguide, ['onchange', 'onbeforechange']); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/2.4.0/intro.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script> 



文章来源: Intro.js not able to fire function between two steps(please check my code)