久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

js實現菜單跳轉效果

瀏覽:120日期:2024-04-10 09:08:32

本文實例為大家分享了js實現菜單跳轉效果的具體代碼,供大家參考,具體內容如下

想要的效果圖:

js實現菜單跳轉效果

直接上代碼

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <title>Document</title> <style> .box { width: 500px; height: 300px; /* border: 1px solid #ccc; */ margin: 50px auto; } span { width: 80px; height: 30px; border: 1px solid #ccc; display: inline-block; text-align: center; line-height: 30px; } .body { margin-top: 5px; width: 450px; border: 1px solid #ccc; height: 250px; background: #eee; } .current { color: red; background: #555; } .body div { display: none; text-align: center; line-height: 250px; } .body .active { display: block } </style></head><body> <div class='box'> <div class='header'> <span class='current'>關注</span> <span>推薦</span> <span>熱點</span> <span>本地</span> <span>段子</span> </div> <div class='body'> <div class='active'>關注:早上吃什么?</div> <div>推薦:中午吃什么?</div> <div>熱點:晚飯吃什么?</div> <div>本地:宵夜吃什么?</div> <div>段子:半夜吃什么?</div> </div> </div> <script> var oSpan = document.querySelectorAll(’span’) var oDiv = document.querySelector(’.body’).children for (let i = 0; i < oSpan.length; i++) { oSpan[i].index = i console.log(oSpan[i].index); oSpan[i].onclick = function () {for (let k = 0; k < oSpan.length; k++) { oSpan[k].classList.remove(’current’)}this.classList.add(’current’)console.log(oSpan[i].index);for (let k = 0; k < oSpan.length; k++) { oDiv[k].classList.remove(’active’)}oDiv[this.index].classList.add(’active’) } } </script></body></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 兴国县| 随州市| 沁阳市| 大港区| 云梦县| 夏津县| 卢湾区| 会同县| 宜黄县| 酉阳| 白玉县| 江津市| 广饶县| 新疆| 资溪县| 青河县| 蒙阴县| 新闻| 耒阳市| 邢台市| 贵溪市| 夹江县| 静安区| 奉化市| 陆川县| 萨迦县| 霍州市| 贵港市| 儋州市| 马山县| 城口县| 定西市| 青铜峡市| 曲阳县| 延川县| 新龙县| 防城港市| 新乡市| 金湖县| 马公市| 彝良县|