当我将html和body height设置为100%时,平滑滚动不起作用
Smooth Scroll doesn't work when I set the html and body height to 100%
html, body {
height: 100%;
min-height: 100%;
position: relative;
}
#home {
height: 100%;
background: url("../img/test.jpg") center no-repeat;
background-size: cover;
}
我使用的平滑滚动JavaScript从CSS-Tricks
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^'//,'') == this.pathname.replace(/^'//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
页面的第一部分是一个完整的页面图像,所以我需要html和body的高度为100%,以设置#home高度为100%,但由于某种原因,当我这样做时,平滑滚动效果不起作用,当我从html和body中删除高度:100%时,它确实起作用了。
有人有同样的问题吗?
使用最小高度:100% 的高度:100% 。
这可能有帮助。非常有用的链接。
http://www.dwuser.com/education/content/quick-guide-adding-smooth-scrolling-to-your-webpages/相关文章:
- Html页面上的多个Base64图像和平滑加载
- Safari(Mac OS)上的jQuery平滑滚动问题
- jquery平滑滚动问题
- 如何正确编程jQuery动画与平滑(导航栏)
- 如何在c3js动态图表上进行平滑(水平)转换
- 使用CSS在选项卡更改时平滑颜色转换
- 如何平滑地设置twitter引导程序进度条的动画
- 有没有写100以上的索引的捷径
- SVG使用Javascript将形状平滑地变形为其他预定义的形状
- 宽度为100%的CSS元素位于视口之外
- 平滑数组中的值
- javascript mootools平滑滚动'x'像素数量
- 如何在jQuery Mobile中设置100%宽度的输入类型日期
- 一旦总和达到100,就禁用其余的数字框
- jQuery平滑滚动
- 平滑更改文本
- jQuery-slideToggle动画不平滑
- jQuery平滑滚动未滚动
- 水平滑块与jQuery: 100%的高度,自动宽度的图像/儿童
- 当我将html和body height设置为100%时,平滑滚动不起作用