jQuery animate:scrolltop 在 Firefox 或 Web Explorer 中不起作用
jQuery animate: scrolltop not working in firefox or web explorer
我有一个导航栏,链接到我页面的其他部分。一切都可以在chrome中运行,但是当我在Firefox或Web浏览器上尝试时,链接只会转到页面顶部。我尝试使用我在其他帖子中看到的(html,正文(解决方案,但它仍然不起作用。
这是代码笔 - http://codepen.io/Davez01d/pen/NxMzYy?editors=0010
这是具体的JavaScript -
$('.to-home').click(function() {
$('html, body').animate({
scrollTop: $('#Home').offset().top - navHeight
},600);
});
$('.to-about').click(function() {
$('html, body').animate({
scrollTop: $('#about-anchor').offset().top - navHeight - aboutPadding + lineBorder
},600);
});
$('.to-portfolio').click(function() {
$('html, body').animate({
scrollTop: $('#portfolio-anchor').offset().top - navHeight + lineBorder
},600);
});
$('.to-contact').click(function() {
$('html, body').animate({
scrollTop: $('#contact-anchor').offset().top - navHeight + lineBorder
},600);
});
编辑:摆弄了一段时间后,我发现它与这部分有关 - navHeight + lineBorder,在我删除它之后,页面会滚动,只是没有到正确的位置,因为它不再应用导航高度。现在我必须弄清楚如何解决这个问题哈哈
你应该更改 var lineBorder = parseInt($('.section-seperator'(.css('
border-top'((; to var lineBorder = $('.section-seperator'(.outerHeight((; 或者在jQuery css函数中使用borderTopWidth。
http://codepen.io/galart/pen/zrbWEZ
$(document).ready(function() {
var lineBorder = $('.section-seperator').outerHeight();
$('#home-btn').addClass('on-section');
$('.to-home').click(function() {
$('html, body').animate({
scrollTop: $('#Home').offset().top - navHeight
},600);
});
$('.to-about').click(function() {
$('html,body').animate({
scrollTop: $('#about-anchor').offset().top - navHeight - aboutPadding + lineBorder
},600);
});
$('.to-portfolio').click(function() {
$('html, body').animate({
scrollTop: $('#portfolio-anchor').offset().top - navHeight + lineBorder
},600);
});
$('.to-contact').click(function() {
$('html, body').animate({
scrollTop: $('#contact-anchor').offset().top - navHeight + lineBorder
},600);
});
});
相关文章:
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 视频HTML没有'无法在Internet Explorer 11上工作
- 在Web应用程序中使用Highcharts javascript
- WebDriverException:tinyMCE未在selenium Web driver java中定义
- Selenium Web驱动程序和javascript
- Windows形成web浏览器控件和Javascript更改的DOM
- 如何将javascript事件从web浏览器wpf控件发送到wpf的c#代码
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- 在调用speak之前预加载Web Speech API
- 如何在visualstudio中调试web api时编辑javascript文件
- Internet Explorer缺少占位符支持,特别是密码字段
- 是否存在React Native“;WEB代码安全防护”;
- 如何在Ionic Android中将Javascript注入到web视图中
- 将复杂对象从angular js传递到web api,它总是返回404
- Internet Explorer中的文本换行错误
- 基于api密钥的NodeJS web服务
- C#Selenium Web驱动程序在Internet explorer中捕获javascript错误
- jQuery animate:scrolltop 在 Firefox 或 Web Explorer 中不起作用
- JavaScript for Each循环适用于除Internet Explorer之外的所有Web浏览器
- 如何强制google chrome/firefox使用Internet explorer web浏览器控件