Can I use multiple intro.js with more than 2 pages?

三世轮回 提交于 2019-12-21 05:55:40

问题


I want to use intro.js with more than two pages. Is it a simple way to do it?


回答1:


Yes, you can. If you look at code for intro.js example with multiple pages https://github.com/usablica/intro.js/tree/master/example/multi-page you can see that first page has code that redirects to second page after user click the button:

<script type="text/javascript">
  document.getElementById('startButton').onclick = function() {
    introJs().setOption('doneLabel', 'Next page').start().oncomplete(function() {
      window.location.href = 'second.html?multipage=true';
    });
  };
</script>

And on the second page we use regex to check if user is going through intro. You will need to add code like that to each page, with url address to the page that should be shown next. If you want to have more than one "intro flows" (since the question title said multiple), you can give them names or numbers. Then, instead of adding multipage=true you can use multipage=beta_version or multipage=1 and use reqex to check if user should see intro, and if yes, which one.

<script type="text/javascript">  
  if (RegExp('multipage', 'gi').test(window.location.search)) {

    document.getElementById('startButton').onclick = function() {
      introJs().setOption('doneLabel', 'Next page')
        .start().oncomplete(function() {
          if (RegExp('multipage=2', 'gi').test(window.location.search)) {
            window.location.href = 'third.html?multipage=2';
          }
          else {
            window.location.href = 'unicorn.html?multipage=3';
          }
        });
      };
  }
</script>

That might be not the nicest code ever :), but ( like Rich said ) without more information I can only guess this is what you want to do? But hopefully, it will give a general idea.




回答2:


if (RegExp('multipage', 'gi').test(window.location.search)) { introJs().setOption('doneLabel', 'Next Page →').start().oncomplete(function() { window.location.href = 'nextpage?multipage=true'; }); }

来源:https://stackoverflow.com/questions/33135590/can-i-use-multiple-intro-js-with-more-than-2-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!