Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firing javascript function between intro.js steps

I am using Intro.js for a guided tour.

I would like to fire javascript functions between some of the steps but I don't manage to. An idea would be to define different intros, and fire the javascript functions between the intros.

Is there a cleaner way to do it ?

like image 382
FredB Avatar asked Jun 17 '13 14:06

FredB


People also ask

How do you trigger a function in Javascript?

onchange: It is triggered when an HTML element changes. onclick: It is triggered when an HTML element is clicked. onmouseover: It is triggered when the mouse is moved over a HTML element. onmouseout: It is triggered when the mouse is moved out of a HTML element.

What is $() in Javascript?

The $() function The dollar function, $(), can be used as shorthand for the getElementById function. To refer to an element in the Document Object Model (DOM) of an HTML page, the usual function identifying an element is: document.


1 Answers

I think I found a better solution, by setting a callback on step changes :

introJs().onchange(function(targetElement) {  
console.log(targetElement.id); 
    switch (targetElement.id) 
        { 
        case "step1": 
            function1();
        break; 
        case "step2": 
            function2();
        break;
        }
}).start();
like image 123
FredB Avatar answered Oct 06 '22 23:10

FredB