header detail 1
header detail 2
世界杯热身赛_世界杯赛程 - toption-intl.com
世界杯热身赛_世界杯赛程 - toption-intl.com

导航栏经过变色 Js 实现案例

Home 2026-01-21 14:29:10 导航栏经过变色 Js 实现案例
世界杯德国瑞士

要求:导航栏鼠标经过颜色变成 #f8b62c,离开后变回 #0b77cf,经过下拉栏同理代码实现:

htmlcssjs12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061

  • 首页
  • 学院概况
    • 学院简介
    • 学院领导
    • 校园风光
    • 荣誉称号
    • 学院校标
    • 学院校训
    • 天麟精神
    • 学院章程
    • 院士风采
  • 机构导航
  • 系部设置
  • 继续教育
  • 数字资源
  • 信息公开
  • 招生就业
    • 招生网
    • 就业网
  • 办公信息
    • 一周工作
    • 通知文件
    • 公文纪要
    • OA系统
  • 公众服务
    • 图书馆
    • 在线学习平台
    • 万方数据
    • 知网
    • 超星汇雅电子书
    • 读秀学术搜索
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495* { margin: 0; padding: 0;}li { list-style: none; font-family: "Microsoft YaHei";}.nav { background: #0b77cf; height: 46px; width: 100%;}div#menu { color: #fff; width: 1183px; margin: auto; display: block; height: 46px;}div#menu ul { margin: 0px; padding: 0px; list-style: none; float: left; z-index: 2; position: relative;}div#menu li { position: relative; margin: 0px; padding: 0px; display: block; overflow: visible; float: left; z-index: 3; color: #fff;}div#menu li a { height: 46px; display: block; float: left; line-height: 46px; text-decoration: none; color: #fff; overflow: hidden; z-index: 4; position: relative; font-size: 16px;}div#menu li span { color: #fff; display: block; width: 107px; text-align: center; z-index: 6; position: relative; font-size: 16px;}div#menu li li { width: 100%; text-indent: 0px; float: none; height: auto;}div#menu ul { margin: 0px; padding: 0px; list-style: none; float: left; z-index: 2; position: relative;}div#menu ul.menu ul { display: none; padding: 0px 0px 0px; background: #1283e1; width: 107px; position: absolute; top: 46px;}.bgc { background-color: #0b77cf!important;}12345678910111213141516171819202122232425var lis = document.querySelector('.menu').children;for (var i = 0; i < lis.length; i++) { lis[i].onmouseover = function () { this.querySelector('span').style.backgroundColor = '#f8b62c' if (this.querySelector('ul')) this.querySelector('ul').style.display = 'block' } lis[i].onmouseout = function () { this.querySelector('span').style.backgroundColor = '' var t = this if (this.querySelector('ul')) { this.querySelector('ul').style.display = 'none' var ulc = this.querySelector('ul').children for (var i = 0; i < ulc.length; i++) { ulc[i].onmouseover = function () { this.querySelector('span').style.backgroundColor = '#f8b62c' t.querySelector('span').className = 'bgc' } ulc[i].onmouseout = function () { this.querySelector('span').style.backgroundColor = '' t.querySelector('span').className = '' } } } }}复杂版htmlcssjs12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  • 首页
  • 学院概况
    • 学院简介
    • 学院领导
    • 校园风光
    • 荣誉称号
    • 学院校标
    • 学院校训
    • 天麟精神
    • 学院章程
    • 院士风采
  • 机构导航
  • 系部设置
  • 继续教育
  • 数字资源
  • 信息公开
  • 招生就业
    • 招生网
    • 就业网
  • 办公信息
    • 一周工作
    • 通知文件
    • 公文纪要
    • OA系统
  • 公众服务
    • 图书馆
    • 在线学习平台
    • 万方数据
    • 知网
    • 超星汇雅电子书
    • 读秀学术搜索
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091* { margin: 0; padding: 0;}li { list-style: none; font-family: "Microsoft YaHei";}.nav { background: #0b77cf; height: 46px; width: 100%;}div#menu { color: #fff; width: 1183px; margin: auto; display: block; height: 46px;}div#menu ul { margin: 0px; padding: 0px; list-style: none; float: left; z-index: 2; position: relative;}div#menu li { position: relative; margin: 0px; padding: 0px; display: block; overflow: visible; float: left; z-index: 3; color: #fff;}div#menu li a { height: 46px; display: block; float: left; line-height: 46px; text-decoration: none; color: #fff; overflow: hidden; z-index: 4; position: relative; font-size: 16px;}div#menu li span { color: #fff; display: block; width: 107px; text-align: center; z-index: 6; position: relative; font-size: 16px;}div#menu li li { width: 100%; text-indent: 0px; float: none; height: auto;}div#menu ul { margin: 0px; padding: 0px; list-style: none; float: left; z-index: 2; position: relative;}div#menu ul.menu ul { display: none; padding: 0px 0px 0px; background: #1283e1; width: 107px; position: absolute; top: 46px;}12345678910111213141516171819202122232425var lis = document.querySelector('.menu').children;for (var i = 0; i < lis.length; i++) { var flag = true; lis[i].onmouseover = function () { if (flag) this.querySelector('span').style.backgroundColor = '#f8b62c' if (this.querySelector('ul')) this.querySelector('ul').style.display = 'block' } lis[i].onmouseout = function () { this.querySelector('span').style.backgroundColor = '' var t = this if (!this.querySelector('ul')) return this.querySelector('ul').style.display = 'none' var ulc = this.querySelector('ul').children for (var i = 0; i < ulc.length; i++) { ulc[i].onmouseover = function () { flag = false; this.querySelector('span').style.backgroundColor = '#f8b62c' } ulc[i].onmouseout = function () { flag = true; this.querySelector('span').style.backgroundColor = '' } } }}

Post navigation

  • Prev Post 为什么做卷腹脖子疼
Copyright © 2088 世界杯热身赛_世界杯赛程 - toption-intl.com All Rights Reserved.
友情链接