Я пытаюсь добавить некоторые функции на сайт, который я не создавал изначально.WordPress - Неверная версия jQuery?
Я правильно enqueueing JQuery, я считаю:
function theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_register_script('main-js', get_stylesheet_directory_uri(). '/includes/main.js', array('jquery'));
wp_enqueue_script('main-js');
}
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
Мой main.js файл довольно прост:
jQuery(window).scroll(function(){
var header = jQuery('.site-header');
var header_height = header.outerHeight;
var scrolltop = jQuery(document).scrollTop();
if (scrolltop >= header_height) {
var header = jQuery('.site-header');
header.addClass('not-fixed');
}
console.log(header_height+','+scrolltop);
})
Однако, когда я проверяю консоль при прокрутке она дает:
[cycle2] --c2 init--
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},4
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},32
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},88
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},152
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},148
main.js?ver=4.6.1:13 function (d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return Y(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)},112
И мой сценарий не работает. Кажется, что в моем скрипте доминирует другая библиотека из какого-то плагина. Любые идеи людей? Я думаю, я мог бы CDN другой версии, но я действительно не хочу загружать миллионы библиотек jQuery.
Спасибо, Matt
ugh, внешнийHeight не является функцией ... –