Запустить функцию во время шага с помощью intro.js - PullRequest
0 голосов
/ 22 декабря 2018

Я попробовал выполнить следующие шаги: Шаг с функцией щелчка в intro.js

, чтобы получить функцию, запускаемую во время шага.Я не добился успеха в получении функции для выполнения, но учебник все еще работает.Конечная цель - заставить функцию вызывать нажатие кнопки.Спасибо за любую помощь.

<script type="text/javascript">
  function startIntro(){
    var intro = introJs();
      intro.setOptions({
        steps: [
          {
            intro: "Welcome to the page!",
            onchange: function(){
                console.log("test");
            },
            onbeforechange: function() {
                console.log("before");
            }
          },
          {
            element: '#step1',
            intro: "You can start doing something by clicking the New Item button."
          },
          {
            element: '.thefilter',
            intro: "You can filter any of the stock items in the table by using the search fields ",
            position: 'bottom'
          }
        ]
      });
      intro.start();
  }
</script>

<a href="javascript:void(0);" onclick="startIntro();"><img style="position:fixed;" src="help.png" /></a>

1 Ответ

0 голосов
/ 22 декабря 2018

Я что-то упустил в примерах, которые дали мне нужное мне направление.

Вот обновленный код.

TLDR;удалил встроенный onchange в шагах и добавил его перед intro.start.Работает!

<script type="text/javascript">
  function startIntro(){
    var intro = introJs();
      intro.setOptions({
        steps: [
          {
            intro: "Welcome to the page!"
          },
          {
            element: '#step1',
            intro: "You can start doing something by clicking the New Item button."
          },
          {
            element: '.thefilter',
            intro: "You can filter any of the stock items in the table by using the search fields ",
            position: 'bottom'
          }
        ]
      });
       intro.onbeforechange(function () {
      if (this._currentStep === 2) {
        console.log('what is happening')
        return false;
      }
    });
      intro.start();
  }
</script>

<a href="javascript:void(0);" onclick="startIntro();"><img style="position:fixed;" src="help.png" /></a>
...