我遇到了第三方脚本无法正常工作的问题。我得到的错误是:
“未捕获的TypeError:jQuery(...)。imageMapper不是函数”
我尝试修复此问题几次,似乎没有任何效果。任何帮助或想法,我们将不胜感激。下面是脚本:
(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();
});
}
})();
最佳答案
在第7行将对mapper_63_execute_scripts();
的调用移至readystate处理程序内。
您试图在浏览器中调用该代码之前将其调用。
关于javascript - jQuery错误阻止imageMapper工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50353037/