更新了Wordpress,我的平滑滚动停止了工作

时间:2016-05-06 21:39:03

标签: javascript jquery wordpress

我刚刚更新到WordPress 4.5,在我做的每个网站中,我的顺利滚动脚本停止工作。当单击包含#的链接时,它用于滚动到相应的容器。我假设我使用的东西在新版本的jQuery中已被弃用或更改,但我找不到答案。

This is one of the sites.

这是我的代码,直到今天一直运行良好。我正在使用jQuery缓动插件:

jQuery("a[href^=#]").click(function(e) {
        e.preventDefault();
        var target_block = jQuery(this).attr("href");
        var target_scroll = jQuery(target_block).offset().top - 100;    
        var window_width = jQuery(window).width(); //retrieve current window width

        if (window_width < 760) {
      target_scroll = target_scroll + 100;
        if (jQuery(window).height() > 560) {
        target_scroll = target_scroll - 60;//compansate for mobile fixed menu
        jQuery("#site-navigation.main-navigation" ).hide(195);//Hide nav
      }
    };
            jQuery("html,body").animate({scrollTop: target_scroll}, 400, 'easeInOutQuart');
    });

1 个答案:

答案 0 :(得分:1)

我刚访问你的一方,你的控制台出错, &#39;错误:语法错误,无法识别的表达式:a [href ^ =#]&#39;

所以,这里你的选择器无效。 #是一个特殊的字符,需要像

一样进行转义
jQuery("a[href*=\\#]").click(function(e){ 

尝试更改以上行。