js实现滚动导航条跟随滑动效果代码
代码语言:html
所属分类:菜单导航
代码描述:js实现滚动导航条跟随滑动效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/normalize.min.css"> <style> @import url('https://fonts.googleapis.com/css2?family=PT+Mono&family=PT+Sans:wght@400;700&display=swap'); /* === Grid and base layout === */ :root { --highlight: #91cb3e; --body-pad-top: 70px; margin: 0; padding: 0; } body { display: grid; margin: 0; padding: var(--body-pad-top) 45px; min-width: 350px; grid: auto / 200px minmax(300px, 500px); align-items: start; justify-content: center; gap: 20px; font: 16px/1.3 'PT Sans', sans-serif; color: #333; background: #edf2f4; } nav { position: -webkit-sticky; position: sticky; left: 0; top: var(--body-pad-top); line-height: 2; } article { margin-top: -50px; padding-top: 50px; } /* === Navbar and marker === */ nav ul { margin: 0; padding-left: 10px; list-style: none; } nav li > ul { padding-left: 30px; } nav a { display: inline-block; color: #7f7f7f; text-decoration: none; transition: all 300ms ease-in-out; } nav li.visible > a { color: #222; transform: translate(5px); } nav svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: -1; } nav path { transition: all 300ms ease; fill: transparent; stroke: var(--highlight); stroke-width: 3px; stroke-dasharray: 0 0 0 1000; stroke-linecap: round; stroke-linejoin: round; } /* === Body contents === */ section[id] { margin: 25px 0; padding: 25px 0; } h1, h2 { margin: 0; padding: 0; font-size: 36px; } h2 { padding-left: 10px; border-left: 4px solid var(--highlight); font-size: 24px; } h1 span, .subheading { display: block; color: #666; font: 700 20px sans-serif; } article a { color: #222; -webkit-text-decoration-color: var(--highlight); text-decoration-color: var(--highlight); } article a:hover { margin: -2px; padding: 2px; border: 0; background: var(--highlight); } code { margin: -2px; padding: 2px; background: rgba(0,0,0,.05); font-family: 'PT Mono', monospace; color: #333; } /* === Adjustments === */ /* Scroll all the way up even if the first section starts a couple hundred pixels down the page */ section:first-of-type { margin-top: -300px; padding-top: 350px; } article, section:last-of-type, section:last-of-type p:last-of-type { margin-bottom: 0; padding-bottom: 0; } </style> </head> <body> <nav> <ul> <li><a href="#intro">Intro</a></li> <li> <a href="#first">First section</a> <ul> <li> <a href="#second">Second section</a> <ul> <li> <a href="#third&qu.........完整代码请登录后点击上方下载按钮下载查看
网友评论0