Jquery WordPress单页样式菜单滚动

Jquery WordPress单页样式菜单滚动,jquery,css,wordpress,Jquery,Css,Wordpress,我正在制作一个单页模板。我尝试使用Smooth scrolling()在其上添加滚动效果,但没有成功。我找不到问题所在,因此非常感谢您的帮助。:) 这是滚动脚本 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.host

我正在制作一个单页模板。我尝试使用Smooth scrolling()在其上添加滚动效果,但没有成功。我找不到问题所在,因此非常感谢您的帮助。:)

这是滚动脚本

$(function() {
  $('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;
      }
    }
  });
});
这是我的functions.php文件

<?php
function theme_js(){

  wp_enqueue_script('scroll_js', get_template_directory_uri() . '/js/scroll.js', array('jquery'), '',true);

}
    add_action('wp_enqueue_scripts','theme_js');

?>

看起来您的PHP格式不正确。试试这个

<?php
function theme_js(){

    wp_enqueue_script('scroll_js', get_template_directory_uri() . '/js/scroll.js', array('jquery'), '',true);

}
add_action('wp_enqueue_scripts','theme_js');

?>

请一次解决一个问题,“我也有突出显示的问题…”。控制台有错误吗?好的。我会慢下来:)。不,我没有收到任何错误@ConcolatoCan先生,您是否建立了一个JSFIDLE示例?问题仍然存在:/你有不止一个问题。您的javascript控制台显示两个错误,一个用于scroll.js,另一个用于contact_me.js。错误是:UncaughtTypeError:undefined不是函数。这意味着jQuery对相关脚本不可用。您已经通过wordpress加载了jQuery,这意味着库已在无冲突模式下加载。您需要在上述两个脚本中更改jQuery调用的包装器代码。请参见上面的代码。我不能保证这就是你所有的问题:-)但那肯定是另一个问题。那救了我的命。谢谢代码有很多问题,但我每天都在努力改进代码和技能。:)
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
    target: '.navbar-fixed-top'
})

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
    $('.navbar-toggle:visible').click();
});
<?php
function theme_js(){

    wp_enqueue_script('scroll_js', get_template_directory_uri() . '/js/scroll.js', array('jquery'), '',true);

}
add_action('wp_enqueue_scripts','theme_js');

?>
jQuery(document).ready(function( $ ) {
    // Your jQuery code here. Now it is safe to be using $ to refer to jQuery.
});