3

I have different DOM elements I want highlighted with the JS library intro.js. The problem seems to be that I can just define one element to be highlighted:

introjs.setOptions({
        steps: [
            {
                element: '.element1',
                intro: 'Lorem ipsum...',
                position: 'bottom'
            },
            {
                element: '.element2',
                intro: 'Lorem ipsum...',
                position: 'top'
            }
        ]
    });

I haven't found any option that lets me choose more than 1 element. Do I have to create more instances of the introjs object to make this possible?

David
  • 131
  • 2
  • 8

2 Answers2

0

By default intro.js start the intro, by adding a gray box layer to the body of the document. This is why if you try to load the intro.js library twice, it willnot work. Only one step can be shown at a time.

If you want, you can load each of the introJs to another container. And they can work together:

You can do it, by start introJs, and specify the parent element. For example:

introJs($('h1').parent()[0]).setOptions({
  steps:[
    {element:$('h1')[0],intro:'hi',position:'bottom'},
  ]}).start();

a2=introJs($('h2').parent()[0]).setOptions({
  steps:[
  {element:$('h2'),intro:'hi',position:'bottom'},
]}).start()

You can synchronize both intro.js instance by using onchange event.

Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117
-1

You should pass the Node (using document.___ or $('.class') ) not only the Selector. check the below snippet.

steps: [
              { 
                intro: "Hello world!"
              },
              {
                element: document.querySelector('#step1'),
                intro: "This is a tooltip."
              },
              {
                element: document.querySelectorAll('#step2')[0],
                intro: "Ok, wasn't that fun?",
                position: 'right'
              },
              {
                element: '#step3',
                intro: 'More features, more fun.',
                position: 'left'
              },
              {
                element: '#step4',
                intro: "Another step.",
                position: 'bottom'
              },
              {
                element: '#step5',
                intro: 'Get it, use it.'
              }
            ]

Reference URL:
https://github.com/usablica/intro.js/blob/master/example/programmatic/index.html

Venkat.R
  • 7,420
  • 5
  • 42
  • 63