作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 jquery 航路点向每个部分添加一个类。重点是要添加“固定”类,当该部分到达视点顶部时,然后再次为上一节删除该类。
我在每个部分之间有一个 push 元素,以确保固定 div 在视口(viewport)中的高度。
效果看起来像一个反向的整页窗帘。
在这里 fiddle :fiddle
标记
<section></section>
<div class="push"></div>
<section></section>
<div class="push"></div>
<section></section>
<div class="push"></div>
<section></section>
CSS
section {
height: 100vh;
z-index: 2;
}
.fixed {
position: fixed;
top:0;
width: 100%;
}
.push {
width: 100%;
height: 100vh;
position: relative;
z-index: 1;
}
Jquery
$('section').each(function(){
var sectionElement = $(this);
var inview = new Waypoint.Inview({
element: sectionElement[0],
entered: function(direction) {
if (direction === 'down') {
$('section').removeClass('fixed');
sectionElement.addClass('fixed');
sectionElement.prev().hide();
} else {
sectionElement.removeClass('fixed');
sectionElement.prev().addClass('fixed');
}
},
});
});
最佳答案
你可以这样做:
.push {
width: 100%;
height: 100vh;
position: fixed;
z-index: 1;
}
关于javascript - 使用航路点在滚动上添加/删除类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32756396/
我是一名优秀的程序员,十分优秀!