我想了两种不同的方法来解决这个问题,但我需要帮助.
I thought of 2 different methods to approaching this, but I need assistance.
我该怎么做?
我目前正在使用 stickyjs.
但我没有看到执行我所要求的功能.
But I don't see a feature for doing what I asked.
demo - http://jsfiddle.net/m6q6j8xL/3/
这是自定义js
在这个演示中,标题变为绿色(fixed),当你到达蓝色时,div 变回normal,当你是从蓝色 div 出来,它变回 fixed
in this demo the header changes to green(fixed) and when you reach to blue div changes back to normal and when u are out from the blue div it changes back to fixed
将填充添加到 div 以便在更改为固定时不会影响窗口滚动
padding is added to div so that it doesn't effect window scroll when changed to fixed
var stickyNavTop = $('.header').offset().top;
function scrolling() {
doc = $(document).height()
hidingtop = $('.hiding').offset().top;
hidingbottom = $('.hiding').position().top + $('.hiding').outerHeight(true) // finding the outer height
if ($(window).scrollTop() > hidingtop && $(window).scrollTop() < hidingbottom) {
$('.header').removeClass('sticky');
$('.container').css('padding-top', '0');
}
}
var stickyNav = function () {
var scrollTop = $(window).scrollTop();
if (scrollTop > stickyNavTop) {
$('.header').addClass('sticky');
$('.container').css('padding-top', '100px');
} else {
$('.header').removeClass('sticky');
$('.container').css('padding-top', '0');
}
};
stickyNav();
$(window).scroll(function () {
stickyNav();
scrolling()
});
这篇关于HTML——我怎样才能“坚持"?到达页面上的特定部分后我的导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何复制 div onclick 事件?How can I duplicate a div onclick event?(如何复制 div onclick 事件?)
从谷歌驱动器打开 htmlopening html from google drive(从谷歌驱动器打开 html)
如何将视频从 Google 驱动器嵌入到网页?How to embed videos from Google drive to webpage?(如何将视频从 Google 驱动器嵌入到网页?)
如何在 iframe 中查看 Google Drive pdf 链接How to view Google drive pdf link in iframe(如何在 iframe 中查看 Google Drive pdf 链接)
使用 Google Drive API 的 HTML2PDFHTML2PDF using Google Drive API(使用 Google Drive API 的 HTML2PDF)
Google 表单:将数据发送到电子表格Google Forms: Send data to spreadsheet(Google 表单:将数据发送到电子表格)