【发布时间】:2017-12-10 18:37:23
【问题描述】:
我正在尝试链接到 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) sn-p 到底在完成什么(我理解它的方式是正在确定我要跳转到的对象是否有内容)。
开发者工具中的错误:
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
需要链接到“程序”页面的是该主页上明亮的彩色按钮。使用导航链接时我也遇到了同样的问题(程序>成功)。
谢谢!
【问题讨论】:
标签: jquery navigation anchor concrete5 page-jump