当我把这个代码放在我的body标签的右上方时,它就起作用了,但当我尝试将它排队时,它就中断了。我在想也许jQuery没有被调用?代码段来自here
功能。PHP
add_action( \'wp_enqueue_scripts\', \'scroll_port\' );
function scroll_port() {
wp_register_script( \'scrolling\', get_template_directory_uri() . \'/js/scroll.js\', array(\'jquery\'), \'\', true );
wp_enqueue_script(\'scrolling\');
}
滚动。JS公司
$(\'a[href*=#]:not([href=#])\').click(function() {
if (location.pathname.replace(/^\\//,\'\') == this.pathname.replace(/^\\//,\'\')
|| location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $(\'[name=\' + this.hash.slice(1) +\']\');
if (target.length) {
$(\'html,body\').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});`