Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Ettrics
STICKY SLIDER NAV V2
Sliding content with sticky tab nav
ES6
Flexbox
React
Angular
Other
ES6
something about es6
Flexbox
something about flexbox
React
something about react
Angular
something about angular
Other
something about other
css
body { font-family: "Century Gothic", "Lato", sans-serif; } a { text-decoration: none; } .et-header { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; -webkit-box-align: center; -ms-flex-align: center; align-items: center; position: fixed; top: 0; left: 0; right: 0; padding: 0 2em; height: 75px; z-index: 2; -webkit-transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); } .et-header--scrolled { background: #fff; box-shadow: 0 0 20px rgba(0, 0, 0, 0.3); } .et-header--move-up { -webkit-transform: translateY(-75px); transform: translateY(-75px); -webkit-transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); } .et-header__logo { color: #000; } .et-header__link { margin-left: 1em; color: #000; } .et-hero-tabs, .et-slide { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -ms-flex-direction: column; flex-direction: column; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; height: 100vh; position: relative; background: #eee; text-align: center; padding: 0 2em; } .et-hero-tabs h1, .et-slide h1 { font-size: 2rem; margin: 0; letter-spacing: 1rem; } .et-hero-tabs h3, .et-slide h3 { font-size: 1rem; letter-spacing: 0.3rem; opacity: 0.6; } .et-hero-tabs-container { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: horizontal; -webkit-box-direction: normal; -ms-flex-direction: row; flex-direction: row; position: absolute; bottom: 0; width: 100%; height: 75px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); background: #fff; z-index: 1; -webkit-transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); } .et-hero-tabs-container--top-first { position: fixed; top: 75px; -webkit-transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1); } .et-hero-tabs-container--top-second { position: fixed; top: 0; } .et-hero-tab { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-flex: 1; -ms-flex: 1; flex: 1; color: #000; letter-spacing: 0.1rem; -webkit-transition: all 0.5s ease; transition: all 0.5s ease; font-size: 0.8rem; } .et-hero-tab:hover { color: white; background: rgba(102, 177, 241, 0.8); -webkit-transition: all 0.5s ease; transition: all 0.5s ease; } .et-hero-tab-slider { position: absolute; bottom: 0; width: 0; height: 6px; background: #66B1F1; -webkit-transition: left 0.3s ease; transition: left 0.3s ease; } @media (min-width: 800px) { .et-hero-tabs h1, .et-slide h1 { font-size: 3rem; } .et-hero-tabs h3, .et-slide h3 { font-size: 1rem; } .et-hero-tab { font-size: 1rem; } }
JavaScript
class StickyNavigation { constructor() { this.currentId = null; this.currentTab = null; this.tabContainerHeight = 70; this.lastScroll = 0; let self = this; $('.et-hero-tab').click(function() { self.onTabClick(event, $(this)); }); $(window).scroll(() => { this.onScroll(); }); $(window).resize(() => { this.onResize(); }); } onTabClick(event, element) { event.preventDefault(); let scrollTop = $(element.attr('href')).offset().top - this.tabContainerHeight + 1; $('html, body').animate({ scrollTop: scrollTop }, 600); } onScroll() { this.checkHeaderPosition(); this.findCurrentTabSelector(); this.lastScroll = $(window).scrollTop(); } onResize() { if (this.currentId) { this.setSliderCss(); } } checkHeaderPosition() { const headerHeight = 75; if ($(window).scrollTop() > headerHeight) { $('.et-header').addClass('et-header--scrolled'); } else { $('.et-header').removeClass('et-header--scrolled'); } let offset = ($('.et-hero-tabs').offset().top + $('.et-hero-tabs').height() - this.tabContainerHeight) - headerHeight; if ($(window).scrollTop() > this.lastScroll && $(window).scrollTop() > offset) { $('.et-header').addClass('et-header--move-up'); $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-first'); $('.et-hero-tabs-container').addClass('et-hero-tabs-container--top-second'); } else if ($(window).scrollTop() < this.lastScroll && $(window).scrollTop() > offset) { $('.et-header').removeClass('et-header--move-up'); $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-second'); $('.et-hero-tabs-container').addClass('et-hero-tabs-container--top-first'); } else { $('.et-header').removeClass('et-header--move-up'); $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-first'); $('.et-hero-tabs-container').removeClass('et-hero-tabs-container--top-second'); } } findCurrentTabSelector(element) { let newCurrentId; let newCurrentTab; let self = this; $('.et-hero-tab').each(function() { let id = $(this).attr('href'); let offsetTop = $(id).offset().top - self.tabContainerHeight; let offsetBottom = $(id).offset().top + $(id).height() - self.tabContainerHeight; if ($(window).scrollTop() > offsetTop && $(window).scrollTop() < offsetBottom) { newCurrentId = id; newCurrentTab = $(this); } }); if (this.currentId != newCurrentId || this.currentId === null) { this.currentId = newCurrentId; this.currentTab = newCurrentTab; this.setSliderCss(); } } setSliderCss() { let width = 0; let left = 0; if (this.currentTab) { width = this.currentTab.css('width'); left = this.currentTab.offset().left; } $('.et-hero-tab-slider').css('width', width); $('.et-hero-tab-slider').css('left', left); } } new StickyNavigation();
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>响应式滑动导航-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号