国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

js實現菜單跳轉效果

瀏覽:151日期: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
相關文章:
主站蜘蛛池模板: 义马市| 临夏市| 前郭尔| 盈江县| 阿勒泰市| 阿荣旗| 淮安市| 精河县| 滨州市| 辉县市| 明溪县| 改则县| 宜兰市| 中宁县| 新河县| 元氏县| 耒阳市| 吴桥县| 波密县| 和静县| 万州区| 睢宁县| 铜陵市| 铜川市| 馆陶县| 运城市| 麦盖提县| 静安区| 武义县| 耿马| 十堰市| 枣庄市| 阆中市| 缙云县| 涟源市| 鲁甸县| 唐海县| 扎赉特旗| 清流县| 胶州市| 溧水县|