我实现了以下代码以启用平滑滚动。问题是它似乎不允许书签链接在不在书签页面上时工作。平滑滚动 -
例如,在下一页上,右侧边栏中的“发布作业”链接/按钮无效 - 单击链接不会执行任何操作 - 甚至不会打开页面。
https://indianashrm.staging.wpengine.com/job-board/graphic-designer/
如果书签链接是书签的页面上,它的工作原理 - 看“发布职位链接/按钮栏
https://indianashrm.staging.wpengine.com/job-board/
任何想法
?<script>
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;
// 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
$('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
});
});
</script>
所以你说的问题是与jQuery的功能。我没有专门设置平滑滚动以仅工作某些页面。我在其他页面上使用平滑滚动,但我现在才认识到这个问题。关于这两种选择,方案一是不可行的。我在代码中使用按钮的完整URL,其他内容正在剥离完整路径。我会寻找其他平滑的滚动解决方案 - 感谢Syden。 – Brett
是的,当你在'/ graphic-designer /'中时,你的jQuery从'this.hash'偏移,比方说,将'this'变成'https://indianashrm.staging.wpengine.com/job-board/ graphic-designer /#createjobposting' - 并且表单在那里不存在,因此undefined显示出来。 – Syden