我正在尝试链接到Concrete5中另一个页面的部分,但无法使其正常工作。当我将鼠标悬停在链接上时,正确的地址会出现在窗口的左下方(Chrome)。但是,当我单击该链接时,什么也没有发生(地址栏中没有出现任何文本,页面上也没有任何变化)。
我的教授似乎认为这是我的 JS 文件中的一个问题,因为我遇到了一个未定义的“顶级”属性错误。
我的链接:
<a href="<?=$this->url('programs');?>#delinquencyprogram">Delinquency Intervention + Prevention</a>
所需的结束位置:
http://maysp.tylerhalldesigns.com/index.php/programs#delinquencyprogram
锚点:
<hr id="delinquencyprogram" class="anchor">
jQuery:
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash,
nav = $('nav');
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
if (nav.height) {
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
}
} // End if
});
});
我对 Jquery/JS 有一个非常初级的了解,并且不确定我是否需要为 nav 创建一个 var 或者 if (nav.length) 片段正在完成什么(我理解它的方式是确定对象是否我跳起来有内容)。
开发者工具中的错误:
Uncaught TypeError: Cannot read property 'top' of undefined
at HTMLAnchorElement.<anonymous> (maysp.js:79)
at HTMLAnchorElement.dispatch (jquery.js:4)
at HTMLAnchorElement.r.handle (jquery.js:4)
如果需要更多信息,我很乐意提供。
该网站可以在这里看到:http: //maysp.tylerhalldesigns.com/index.php
需要链接到“程序”页面的是该主页上明亮的彩色按钮。使用导航链接(程序>成功)时,我也遇到了同样的问题。
谢谢!