javascript - jQuery 错误导致 imageMapper 无法工作

标签 javascript jquery

我遇到了第三方脚本无法运行的问题。我得到的错误是:

"Uncaught TypeError: jQuery(...).imageMapper is not a function"

我尝试过多次修复此问题,但似乎没有效果。非常感谢任何帮助或想法。下面是脚本:

(function() {
  var mapper_63_loadScript = function(url, success) {
    var script = document.createElement('script');
    script.src = url;
    var head = document.getElementsByTagName('head')[0],
      done = false;
    script.onload = script.onreadystatechange = function() {
      if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
        done = true;
        success();
        script.onload = script.onreadystatechange = null;
        head.removeChild(script);
      }
    };
    head.appendChild(script);
  };

  var mapper_63_execute_scripts = function() {
    jQuery('.imagemapper63-wrapper').imageMapper({
      itemOpenStyle: 'click',
      itemDesignStyle: 'responsive',
      responsiveWidth: 600,
      transformSmall: 1,
      oldResponsive: 0,
      animateOther: 1000,
      pinScalingCoefficient: 1,
      advancedPinOptions: true,
      pinClickAction: "content",
      pinHoverAction: "my_content",
      useTransitions: '1',
      animationDuration: 170,
      mapOverlay: true
    });
  };

  if ((typeof jQuery === 'undefined') || (parseInt(jQuery.fn.jquery) === 1 && parseFloat(jQuery.fn.jquery.replace(/^1\./, "")) < 9.1)) {
    mapper_63_loadScript('//code.jquery.com/jquery-2.2.3.min.js', function() {
      mapper_63_loadScript('https://easy-image-mapper.herokuapp.com/shopify_image_mapper.js?shop=mustaevusa.myshopify.com', function() {
        mapper_63_execute_scripts();
      });
    });
  } else {
    mapper_63_loadScript('https://easy-image-mapper.herokuapp.com/shopify_image_mapper.js?shop=mustaevusa.myshopify.com', function() {
      mapper_63_execute_scripts();
    });
  }
})();

最佳答案

将对 mapper_63_execute_scripts(); 的调用移至第 7 行的就绪状态处理程序内部。

您正尝试在该代码在浏览器中可用之前调用该代码。

关于javascript - jQuery 错误导致 imageMapper 无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50353037/

相关文章:

javascript - jQuery 的 attr() 函数用 html 特殊字符破坏 html?

javascript - 如何获取 DIV 的值

javascript - 完全数据丢失 Ionic/Cordova LocalStorage 和 Websql iOS 8.4.1

javascript - 访问 Firebase push() 子级

javascript - 选择与变量匹配的单选按钮

javascript - 如何将 localStorage 从 JS 发送到 PHP 文件(?)

javascript - 带有 CellEditing 的 ExtJs 4 GridPanel : data entered is lost on failed validation

javascript - 使用 JavaScript 的 `window.cookie` 持久化 CSS 状态

javascript - 从 jQuery 1.7.1 更新到 jQuery 1.10.2

JavaScript 变量未定义错误?