【发布时间】:2016-07-04 20:25:47
【问题描述】:
我有一个包含一些菜单项的菜单。所有这些都是这样定义的:
<li><a href="#about" target="_self" title="about">About</a></li>
链接到 pdf 的除外:
<li><a href="pdf/theDocument.pdf" target="_blank">My Pdf</a></li>
现在我想在我的页面上添加一些平滑滚动,当点击链接到 pdf 的锚点除了。我有以下 jQuery 代码,它添加了滚动效果,但禁用了在新选项卡中打开 pdf 文件。这是我实现滚动的代码。
$(document).on('click', 'a', function(event){
event.preventDefault();
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 700);
});
任何想法如何为除链接 pdf 的锚之外的所有锚添加滚动效果吗?谢谢!
【问题讨论】:
-
您可以在点击事件中使用
if ($(this).attr("href") == "pdf/theDocument.pdf")
标签: javascript jquery html pdf anchor