【问题标题】:qtip tooltip for Bigcommerce StencilBigcommerce Stencil 的 qtip 工具提示
【发布时间】:2018-08-23 21:36:45
【问题描述】:

我正在尝试在我的 bigcommerce 基石主题中创建此工具提示。

我已遵循所有步骤。但图片本身并没有出现在我的网站上。

它显示在我的内容中

<span id="service-time" style="display: none;">[INFO TO BE SHOWN WITH THE TOOLTIP]</span>

我用

`<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>`

`<script type="text/javascript" src="/content/jquery.qtip-1.0.0-rc3.js"></script>`

这是 tooltips.js

<script>
    $(document).ready(function() {

  $("div[data-product-option-change] .form-field").each(function() {

 var optionLabel = $(this).sibling('.form-label small');

    var optionLabelText = optionLabel.children("label.form-label.form-label--alternate.form-label--inlineSmall").children(".form-label").text();
    // check that optionLabelText is not an empty string
    if ($("img", this).length < 1 && slugify(optionLabelText).trim().length) {
      $(this).sibling('.form-label small')
        .children("label.form-label.form-label--alternate.form-label--inlineSmall")
        .children(".form-label")
        .append("&nbsp;<div class='help_div' style='display: inline;'><img src='/content/help.gif'  alt='" + optionLabelText + "'/></div>");
    }
}
  });

  $('.help_div').each(function() {

    var slug = slugify($("img", this).prop('alt'));
    var html = $("#" + slug).html();
    var titleq = $("img", this).prop('alt').replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
    titleq = "<strong style='font-size: 12px'>" + titleq + "</strong><br/>"
    if (!html) html = "Description not available yet."

    $(this).qtip({
      content: titleq + html,
      position: {
        corner: {
          tooltip: 'topRight',
          target: 'bottomLeft'
        }
      },
      style: {
        tip: {
          corner: 'rightTop',
          color: '#6699CC',
          size: {
            x: 15,
            y: 9
          }
        },
        background: '#6699CC',
        color: '#FFFFFF',
        border: {
          color: '#6699CC',
        }
      }
    });

  });

  function slugify(text) {
    text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
    text = text.replace(/-/gi, "_");
    text = text.replace(/^\s+|\s+$/g, "");
    text = text.replace(/\s/gi, "-");
    text = text.toLowerCase();
    return text;
  }

});
</script>

这是我的 HTML:

<div data-product-option-change="" style="">
<div class="form-field" data-product-attribute="set-select">
    <label class="form-label form-label--alternate form-label--inlineSmall" for="attribute_250">
        Service Time:

            <small>Required</small><span class="toolTip" title=""></span>
    </label>


</div>



<div class="form-field" data-product-attribute="input-text">
    <label class="form-label form-label--alternate form-label--inlineSmall" for="attribute_252">
        Event Name:

            <small>Required</small><span class="toolTip" title=""></span>
    </label>


</div>
</div>

<span id="service-time" style="display: none;">[INFO TO BE SHOWN WITH THE TOOLTIP]</span>

为什么它不起作用?

【问题讨论】:

  • 在您的商店中,选项值的类实际上是“productAttributeValue”吗?看起来这些说明可能是为我们的旧版主题平台编写的,并且类名可能不同。
  • 您好,感谢您的回复。我检查了一下,似乎这个类实际上是 productOptions-list-item。我尝试更改班级名称。但它仍然不起作用。有什么想法吗?
  • 控制台有错误吗?
  • 完全没有错误.. 已经工作了好几天,但无济于事。这是我试图完成的页面的链接:store-cvnscu0qdh.mybigcommerce.com/rostrum
  • @KarenWhite 我已经配置了 HTML 部分。我在这里做错了什么?请帮忙!

标签: jquery tooltip bigcommerce qtip jquery-ui-tooltip


【解决方案1】:

您的 js 中似乎存在一些语法错误,并且类选择器仍然存在一些问题。试试这个:

    $(document).ready(function() {

$(".form-field").each(function() {

var optionLabel = $(this).children('.form-label');
var optionLabelText = optionLabel.text();


if($("img", this).length < 1) {
$(this).children('.form-label.form-label--alternate.form-label--inlineSmall').append("&nbsp;<div class='help_div' style='float:right;'><img src='/content/help.gif'  alt='"+optionLabelText+"'/></div>");
}

});


  $('.help_div').each(function() {

    var slug = slugify($("img", this).prop('alt'));
    console.log(slug);
    var html = $("#" + slug).html();
    var titleq = $("img", this).prop('alt').replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
    titleq = "<strong style='font-size: 12px'>" + titleq + "</strong><br/>"
    if (!html) html = "Description not available yet."

    $(this).qtip({
      content: titleq + html,
      position: {
        corner: {
          tooltip: 'topRight',
          target: 'bottomLeft'
        }
      },
      style: {
        tip: {
          corner: 'rightTop',
          color: '#6699CC',
          size: {
            x: 15,
            y: 9
          }
        },
        background: '#6699CC',
        color: '#FFFFFF',
        border: {
          color: '#6699CC',
        }
      }
    });

  });

  function slugify(text) {
    text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
    text = text.replace(/-/gi, "_");
    text = text.replace(/^\s+|\s+$/g, "");
    text = text.replace(/\s/gi, "-");
    text = text.toLowerCase();
    return text;
  }

  });

我能够使用上面的代码和您提到的教程来完成这项工作,但有几点可能会有所帮助:

  • 您使用的 qtip 插件版本 (1.0.0) 已弃用,并且与 jQuery 1.9x 及更高版本不兼容。我不得不使用 jQuery 1.6x 来避免来自 $.browser 的错误。见:http://qtip2.com/guides
  • 确保按以下顺序引用脚本:
    1. jQuery 库
    2. qtip 插件
    3. 工具提示.js

控制台日志语句将在循环每个选项时打印 slug 变量,您需要将其设置为跨度 ID 以指定每个选项的消息。

希望这会有所帮助!

【讨论】:

  • 嗨!谢谢回复!真的很需要。我设法得到了“?”的形象。显示。但是当我将鼠标悬停在它上面时,不会出现文本消息或弹出窗口......我错过了什么?
  • 您收到.qtip is not a function 的控制台错误。所以 qtip jquery 插件文件没有被识别。你在哪里引用你的 jquery.qtip-1.0.0-rc3.js 文件?
  • 我现在开始工作了!但是当我从仪表板的产品描述中控制它时,它没有出现..工具提示的内容..
  • 尝试控制台记录 slug 变量以进行故障排除。无论打印出什么,您都需要在产品描述中输入跨度 ID 以设置提示内容。例如&lt;span id="event-date--------------required" style="display:none"&gt;Hello, this is my tooltip text!&lt;/span&gt;
  • 您好,我尝试进行故障排除。但是没有产生任何结果。一直在努力寻找跨度 ID。没有工作:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-29
相关资源
最近更新 更多