最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ignore missing element for the tour in tour.js - Stack Overflow

programmeradmin4浏览0评论

I am using intro.js in a dynamic page and if all the elements provided are present, the tour goes fine without any issues.

But if any of the element is not present, the page being dynamically generated, the tour stops and have to press NEXT button twice to proceed further.

Is there any way to skip the step altogether if the element is not present?

Example:

intro.setOptions({
   steps[
      {"element":".ow_status","intro":"status"}, 
      {"element":".ow_mailbox","intro":"mailbox"},
      {"element":".ow_test","intro":"test"}
   ] 
});

In the above example, if the element with class ow_mailbox is not present, the tour stops in the middle and it shows 3 steps although only 2 is with valid element.

I am using intro.js in a dynamic page and if all the elements provided are present, the tour goes fine without any issues.

But if any of the element is not present, the page being dynamically generated, the tour stops and have to press NEXT button twice to proceed further.

Is there any way to skip the step altogether if the element is not present?

Example:

intro.setOptions({
   steps[
      {"element":".ow_status","intro":"status"}, 
      {"element":".ow_mailbox","intro":"mailbox"},
      {"element":".ow_test","intro":"test"}
   ] 
});

In the above example, if the element with class ow_mailbox is not present, the tour stops in the middle and it shows 3 steps although only 2 is with valid element.

Share Improve this question edited Jan 15, 2014 at 16:05 Liam 29.7k28 gold badges137 silver badges200 bronze badges asked Jan 15, 2014 at 15:59 PurusPurus 5,7999 gold badges52 silver badges92 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 19

We can filter the array and only return elements that exist. The new options would look like this:

intro.setOptions({
   steps: [
      {"element":".ow_status","intro":"status"}, 
      {"element":".ow_mailbox","intro":"mailbox"},
      {"element":".ow_test","intro":"test"}
   ].filter(function (obj) {
      return $(obj.element).length;
   })
});

I had a similar problem but on a responsive template. Depending on viewport, my elements were present but were hidden. I had to use this code instead.

intro.setOptions({
  steps: [
    {"element":".ow_status","intro":"status"}, 
    {"element":".ow_mailbox","intro":"mailbox"},
    {"element":".ow_test","intro":"test"}
  ].filter(function (obj) {
    $(obj.element).is(':visible');
  })
});

To improve just a bit the answer of @Neil and allow floating steps too, just add this:

intro.setOptions({
   steps: [
      {"element":".ow_status","intro":"status"}, 
      {"element":".ow_mailbox","intro":"mailbox"},
      {"element":".ow_test","intro":"test"}
   ].filter(function (obj) {
      return $(obj.element).length || obj.element == ".introjsFloatingElement";;
   })
});
发布评论

评论列表(0)

  1. 暂无评论