[英]Javascript Uncaught Type Error on Live environment only, works fine on Dev
我有一個莫名其妙的問題。 一小部分javascript,用於計數到Wordpress子主題中設置的並根據父主題改編的給定數字。 該腳本在我的開發環境中運行完美,但是在使用完全相同的代碼庫的實時環境中,代碼失敗並返回熟悉的代碼
Uncaught TypeError: undefined is not a function
它在第一次運行時似乎工作正常,但在隨后的運行中失敗。 實時服務器上失敗的特定代碼行是這樣的:
$(this).waypoint(function(direction) {
我檢查並仔細檢查了代碼庫(相同),並檢查了所有文件的權限(全部可讀)。 我完全困惑-有人能對此有所了解嗎?
您可以在這里看到它http://bit.ly/1vUX8pf
在示例中,失敗的是最上面的計數器。 從底部的櫃台稍微修改了代碼,繼續正常工作。 說我不知所措會輕描淡寫!
完整代碼在這里:
(function($) {
function audioSecondsInit() {
$('.nectar-audioseconds').each(function() {
if($(this).has('[data-symbol]')) {
if($(this).attr('data-symbol-pos') == 'before') {
$(this).find('.number').prepend($(this).attr('data-symbol'));
} else {
$(this).find('.number').append($(this).attr('data-symbol'));
}
}
});
if(!$('body').hasClass('mobile')) {
$('.nectar-audioseconds').each(function() {
// FAILS HERE >>>
$(this).waypoint(function(direction) {
var $endNum = parseInt($(this).find('.number span').text());
$endNum = $endNum + (23671233 * Math.floor(( (new Date()) - Date.parse('12/01/2014') ) / 86400000));
$(this).find('.number span').countToFormat({
from: 0,
to: $endNum,
speed: 1500,
refreshInterval: 30
});
}, { offset: '105%', triggerOnce: true });
});
}
}
setTimeout(function(){
audioSecondsInit();
},100);
$.fn.countToFormat = function (options) {
console.log("countToFormat");
options = options || {};
return $(this).each(function () {
var settings = $.extend({}, $.fn.countTo.defaults, {
from: $(this).data('from'),
to: $(this).data('to'),
speed: $(this).data('speed'),
refreshInterval: $(this).data('refresh-interval'),
decimals: $(this).data('decimals')
}, options);
var loops = Math.ceil(settings.speed / settings.refreshInterval),
increment = (settings.to - settings.from) / loops;
var self = this,
$self = $(this),
loopCount = 0,
value = settings.from,
data = $self.data('countTo') || {};
$self.data('countTo', data);
if (data.interval) {
clearInterval(data.interval);
}
data.interval = setInterval(updateTimer, settings.refreshInterval);
render(value);
function updateTimer() {
value += increment;
loopCount++;
render(value);
if (typeof(settings.onUpdate) == 'function') {
settings.onUpdate.call(self, value);
}
if (loopCount >= loops) {
// remove the interval
$self.removeData('countTo');
clearInterval(data.interval);
value = settings.to;
if (typeof(settings.onComplete) == 'function') {
settings.onComplete.call(self, value);
}
}
}
function render(value) {
var formattedValue = settings.formatter.call(self, value, settings);
$self.html(numberWithCommas(formattedValue));
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
});
};
})(jQuery);
在您的網站上,我看不到waypoint.min.js
。
在首頁,我調試了它,發現它在函數的第一次處理時出現.waypoint
,因為.waypoint
不存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.