忽略tour.js中游览的缺失元素 [英] Ignore missing element for the tour in tour.js

查看:52
本文介绍了忽略tour.js中游览的缺失元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在动态页面中使用了intro.js,如果提供的所有元素都存在,那么浏览过程将顺利进行,没有任何问题.

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

但是,如果不存在任何元素,则会动态生成页面,游览将停止,并且必须按两次NEXT(下一步)按钮才能继续进行操作.

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?

示例:

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

在上面的示例中,如果不存在带有ow_mailbox类的元素,则巡视在中间停止,并且显示3个步骤,尽管只有2个具有有效元素.

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.

推荐答案

我们可以过滤数组,只返回存在的元素.新选项如下所示:

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;
   })
});

这篇关于忽略tour.js中游览的缺失元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆