一 网易严选分类效果图
分析:
二 思路分析
从彩妆护肤往下移鼠标,就变成了海鲜水产的2,3级分类了
但是使用 display:none、visibility:hidden 这两个属性,问题就不存在了
三 实现核心代码
html:
<!-- 分类 --> <li v-for="(item,i) in categoryList" :key="i" class="categoryBox" :class="{‘active‘:i === choosePage}" @click="goCategoryPage(item.id,i)" @mouseover="mouseoverEvent(item.children)" > <div class="categoryName cursor">{{item.categoryName}}</div> <ul class="categoryList2" ref="categoryPopRef"> <li v-for="(stem,d) in categoryList2" :key="d" class="categoryItem2" > <div class="categoryName2 cursor" @click="goCategoryPage(stem.id,i)" >{{stem.categoryName}}</div> <ul class="categoryList3"> <li v-for="(titem,t) in stem.children" :key="t" class="categoryItem3" @click="goCategoryPage(titem.id,i)" > <div class="categoryName3 cursor">{{titem.categoryName}}</div> </li> </ul> </li> </ul> </li>
css:
li { padding-left: 2px; padding-right: 30px; &.categoryBox { // background: rgba(0, 0, 0, 0.5); color: #666; .categoryName { font-weight: bold; position: relative; } .categoryList2 { position: absolute; min-width: 100%; max-width: 120%; top: 70px; left: 50%; transform: translateX(-50%); background-color: #fff; display: flex; padding: 20px 30px; min-height: 200px; border: 1px solid #dcdcdc; color: #666; display: none; // visibility:hidden; .categoryItem2 { // background: rgba(0, 0, 0, 0.5); margin-right: 20px; font-size: 16px; min-width: 100px; max-width: 200px; line-height: 36px; .categoryName2 { font-weight: bold; min-width: 100px; max-width: 200px; border-bottom: 1px solid #bdbdbd; &:hover { // color: #5683ea; color: #f4364c; } } .categoryList3 { padding: 20px 0; // width: 100%; display: flex; flex-wrap: wrap; max-height: 400px; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; .categoryItem3 { .categoryName3 { font-weight: normal; width: 100px; // background: rgba(0, 0, 0, 0.5); margin-right: 10px; font-size: 15px; line-height: 26px; &:hover { // color: #5683ea; color: #f4364c; } } } } } } &:hover { .categoryName{ color: #f4364c; } .categoryList2 { display: flex; // visibility: visible; } } &.active { font-weight: bold; color: #666; } } }
四 知识梳理
display:none、visibility:hidden、opacity:0、overflow:hidden之间区别:
分享一刻:
今年5月是 Java 语言诞生25周年,JetBrains 公司在官方博客里面,总结了 Java 语言的25个优点。
原文:https://www.cnblogs.com/huangaiya/p/13213730.html