File tree Expand file tree Collapse file tree 1 file changed +45
-1
lines changed
Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Original file line number Diff line number Diff line change 120120 margin-top : 5px ;
121121 }
122122
123- .dropdown : hover . dropdown -content {
123+ .dropdown-content . show {
124124 display : block;
125125 }
126126
@@ -1197,9 +1197,53 @@ <h3>📝 文本内容</h3>
11971197 } , 3000 ) ;
11981198 }
11991199
1200+ // 下拉菜单控制逻辑
1201+ let dropdownTimer = null ;
1202+
1203+ function setupDropdownEvents ( ) {
1204+ const dropdown = document . querySelector ( '.dropdown' ) ;
1205+ const dropdownContent = document . querySelector ( '.dropdown-content' ) ;
1206+
1207+ if ( ! dropdown || ! dropdownContent ) return ;
1208+
1209+ // 鼠标进入下拉菜单区域
1210+ dropdown . addEventListener ( 'mouseenter' , function ( ) {
1211+ if ( dropdownTimer ) {
1212+ clearTimeout ( dropdownTimer ) ;
1213+ dropdownTimer = null ;
1214+ }
1215+ dropdownContent . classList . add ( 'show' ) ;
1216+ } ) ;
1217+
1218+ // 鼠标离开下拉菜单区域
1219+ dropdown . addEventListener ( 'mouseleave' , function ( ) {
1220+ // 设置延迟隐藏,给用户时间移动到菜单项
1221+ dropdownTimer = setTimeout ( function ( ) {
1222+ dropdownContent . classList . remove ( 'show' ) ;
1223+ } , 200 ) ; // 200ms延迟
1224+ } ) ;
1225+
1226+ // 鼠标进入下拉菜单内容区域
1227+ dropdownContent . addEventListener ( 'mouseenter' , function ( ) {
1228+ if ( dropdownTimer ) {
1229+ clearTimeout ( dropdownTimer ) ;
1230+ dropdownTimer = null ;
1231+ }
1232+ } ) ;
1233+
1234+ // 鼠标离开下拉菜单内容区域
1235+ dropdownContent . addEventListener ( 'mouseleave' , function ( ) {
1236+ dropdownTimer = setTimeout ( function ( ) {
1237+ dropdownContent . classList . remove ( 'show' ) ;
1238+ } , 200 ) ; // 200ms延迟
1239+ } ) ;
1240+ }
1241+
12001242 // 页面加载时检查用户登录状态
12011243 document . addEventListener ( 'DOMContentLoaded' , function ( ) {
12021244 checkUserLogin ( ) ;
1245+ // 设置下拉菜单事件
1246+ setupDropdownEvents ( ) ;
12031247 } ) ;
12041248 </ script >
12051249</ body >
You can’t perform that action at this time.
0 commit comments