平滑滚动jquery+修复导航错误
Smooth scrolling jquery + fixed navigation bug
我正在创建一个单页网站。
我在应用平滑滚动和顶部固定菜单时遇到了问题。当我点击它的链接时,菜单就会消失并出现错误。
以下是出现错误的网站:http://bitcast.com.br/
我用于平滑滚动效果的Javascript代码如下(来自CSSTricks.com):
<script type="text/javascript">
$(document).ready(function() {
function filterPath(string) {
return string
.replace(/^'//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/'/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');
$('a[href*=#]').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
var $target = $(this.hash), target = this.hash;
if (target) {
var targetOffset = $target.offset().top;
$(this).click(function(event) {
event.preventDefault();
$(scrollElem).animate({scrollTop: targetOffset}, 800, function() {
location.hash = target;
});
});
}
}
});
// use the first element that is "scrollable"
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return [];
}
});
</script>
如果删除
function() {
location.hash = target;
}
在滚动动画上,它会很好地工作。
相关文章:
- 第二个引导程序导航栏链接打开第一个(错误的)导航栏;jquery
- 使用标签页导航时Chrome Windows中的Angular ng-select错误
- 反应.js - 导航路由时控制台中的错误
- 在执行漂亮的照片库后从“导航”中删除类“粘性”的错误
- 项目符号导航中的 JSSOR 滑块错误
- 使用量角器网络驱动程序进行 Safari 历史记录导航的未知错误
- 页面导航上的 requireJS 错误
- 导航栏错误
- Javascript:如何在使用 window.location.href = url 导航到的页面上捕获错误
- 在 jqgrid 中实现内联导航的错误
- require(processing-js) 抛出引用错误:找不到导航器
- Jquery 移动导航栏填充错误:太窄
- 请帮我在Bootstrap 3导航栏中找到错误
- 更改引导程序后的移动菜单切换错误'的移动导航断点
- 带错误的Onsen UI导航:您不能提供no"ons页”;元素到“;ons导航器”;当返回第一页时
- 平滑滚动jquery+修复导航错误
- 404 jQuery导航错误
- firefox中的Javascript页面导航错误
- SmartAdmin HTML版本导航错误-在多级导航上加倍锚
- 使用推送状态/弹出状态获取导航错误- JavaScript页面更改