Javascript jquery TypeError:a在wordpress中为空
我正在wordpress中实现jquery平滑滚动定位。在首页上似乎一切正常,没有错误,但是,当我在任何其他页面上时,我得到jquery TypeError:main.js中的a是null错误 这是我的链接结构,首页上有几个部分:Javascript jquery TypeError:a在wordpress中为空,javascript,jquery,html,wordpress,Javascript,Jquery,Html,Wordpress,我正在wordpress中实现jquery平滑滚动定位。在首页上似乎一切正常,没有错误,但是,当我在任何其他页面上时,我得到jquery TypeError:main.js中的a是null错误 这是我的链接结构,首页上有几个部分: <li id="menu-item-631" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-631"><a class="anchor_scroll"
<li id="menu-item-631" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-631"><a class="anchor_scroll" href="#services">Services</a></li>
<li id="menu-item-632" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-632"><a class="anchor_scroll" href="#about">About</a></li>
<li id="menu-item-633" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-633"><a class="anchor_scroll" href="#partners">Partners</a></li>
此代码位于单独的js文件中,该文件加载在文档的头部。正如我之前所说,在首页上没有错误,只有在网站的内页上
还有第二个问题与js代码有关。如何更改所需的滚动位置?我需要像offset().top-150这样的东西,但当我这样做时,它会滑动到那个位置,然后跳150到前面的位置,因为它将只是offset().top
谢谢你能提供提琴或url吗?你能提供main.js中的代码吗?因为代码的另一部分似乎在除main之外的页面上产生错误,因此滚动插件的执行被中断。wordpress现在安装在本地机器上。在fiddle中重现相同的问题非常困难,因为我安装了几个插件等等。我猜main.js是一个jquery库文件或类似文件。它很大。根据firebug,我在第48行得到了一个错误。这是firebug中错误的链接:这可能是google maps api的错误吗?这是关于错误的更多细节:TypeError:a是空的第48行
<li id="menu-item-631" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-631"><a class="anchor_scroll" href="index.php#services">Services</a></li>
<li id="menu-item-632" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-632"><a class="anchor_scroll" href="index.php#about">About</a></li>
<li id="menu-item-633" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-633"><a class="anchor_scroll" href="index.php#partners">Partners</a></li>
(function($){
var jump=function(e)
{
if (e){
e.preventDefault();
var target = $(this).attr("href");
}else{
var target = location.hash;
}
$('html,body').animate(
{
scrollTop: $(target).offset().top
},1500,'swing',function()
{
location.hash = target;
});
}
$('html, body').hide()
$(document).ready(function()
{
$('a[href^=#]').bind("click", jump);
if (location.hash){
setTimeout(function(){
$('html, body').scrollTop(0).show()
jump()
}, 0);
}else{
$('html, body').show()
}
});
})(jQuery)