usablica / intro.js

Lightweight, user-friendly onboarding tour library
http://introjs.com
Other
22.83k stars 2.59k forks source link

How can I set in JSON Step number / priority - Or better way to start from specific part? #436

Closed iq-dot closed 4 years ago

iq-dot commented 9 years ago

Is there a way to define the step number in the JSON object? e.g.:

{
element: '#mybtn',
intro: 'button',
step: 2
}

?

I am basically trying to create a multi-section intro, which due to the tech stack (AngularJS) and single page nature, I need to rely on step numbers to specifically sub-divide parts of my IntroJS object using steps.

Ideally it would be great if I could sub-divide using labels instead:

{
section1: [
 {
   element: '#mybtn',
   intro: 'button',
   step: 2
  }
]

IntroJS.start('section1');

Now I don't think something like that exist but the step numbers exist in the 'data-step' attributes so is there an equivalent in the programmatic way?

Thanks

krngrvr09 commented 9 years ago

One of the ways is to define different tours for different sections.

Eg.

var feature1 = introJs();
var feature2 = introJs();

feature1.setOptions({
    steps:[
        {
            ...
        },
        {
            ...
        },

]
})
.oncomplete(function(){
    setTimeout(function(){ feature2.start(); },500)
})

feature1.setOptions({
    steps:[
        {
            ...
        },
        {
            ...
        },

]
});
donaldwasserman commented 9 years ago

I took a slightly different approach by using a custom data-attribute, then match that 'token' against my JSON array:

{
        "token": "global_pages",
        "steps": [
          {
            "intro": "asdf."
          },
<button class="button js-start-tour" data-token="global-pages>Click Me!</button>

then

(see underscore docs, btu you can do this natively as well...)

$('.js-start-tour).on('click', function() {
  var tour = _.findWhere(parsedJson, {token: token});

pageTour = introJs();

//you can jam in some other options into that tour variable.
pageTour.setOptions({steps: tour.steps})
pageTour().start()
});
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.