|
|

楼主 |
发表于 2025-2-15 13:33
|
显示全部楼层
代码
- <style>
- #tz { margin: auto; width: 760px; height: 640px; border: 1px solid gray; position: relative; }
- #artwrap { position: absolute; left: 0; top: 0; width: 460px; height: 600px; overflow: hidden; display: flex; /*flex-direction: column; /*纵向*/*/ }
- #artwrap > div { flex-wrap: nowrap; flex-shrink: 0; width: 100%; height: 100%; background: #eee; padding: 6px 10px; box-sizing: border-box; }
- #artwrap div p, #artwrap div h2 { margin: 8px; }
- #artwrap h2 { text-align: center; }
- #artwrap p { fontsize: 16px; }
- #btnwrap { position: absolute; left: 0; bottom: 2px; width: 460px; text-align: center; }
- .btn { margin: 4px; width: 26px; height: 26px; border: 2px dotted silver; border-radius: 50%; text-align: center; line-height: 26px; font-size: 14px; cursor: pointer; display: inline-block; }
- .btn:hover { color: red; background: silver; }
- .redBorder { border-color: red; cursor: default; }
- </style>
- <div id="tz">
- <div id="artwrap">
- <div>
- <h2>第一页标题</h2>
- <p>具体内容</p>
- <p>…………</p>
- </div>
- <div>
- <h2>第二页标题</h2>
- </div>
- <div>
- <h2>第三页标题</h2>
- </div>
- <div>
- <h2>第四页标题</h2>
- </div>
- <div>
- <h2>第五页标题</h2>
- </div>
- <div>
- <h2>第六页标题</h2>
- </div>
- </div>
- <div id="btnwrap">
- <span class="btn redBorder">1</span>
- <span class="btn">2</span>
- <span class="btn">3</span>
- <span class="btn">4</span>
- <span class="btn">5</span>
- <span class="btn">6</span>
- </div>
- </div>
- <script>
- var divs = artwrap.querySelectorAll('div'),
- btns = document.querySelectorAll('.btn');
- btns.forEach((btn,key) => {
- btn.onclick = () => {
- divs[key].scrollIntoView({behavior: 'smooth', block: 'center', inline: 'center'});
- btns.forEach((b,k) => {
- b.className = k === key ? 'btn redBorder' : 'btn';
- });
- }
- });
- </script>
复制代码
|
评分
-
| 参与人数 2 | 威望 +80 |
金钱 +160 |
经验 +80 |
收起
理由
|
花飞飞
| + 30 |
+ 60 |
+ 30 |
很给力! |
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|