想必大家在开发前端页面时,肯定少不了显示隐藏层这一技术点。那么我简单粗暴地总结了以下两个小demo.

要实现该截图的功能:鼠标移动到我的好友这个选项卡时,灰色的隐藏层就会出现。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUkAAAFzCAIAAAA8CWw0AAAcL0lEQVR4nO2dzXPbRpqHefNhznPawx73yEtOuc3/MFee9ryXObFWVlRlO1FYcqKaiqJEVbE9rk1JldXGpj2Kyk4sZ0ZWebdseqwZ0WXXRpkaKWuKtEOaIkSZZChiDyCIBtANgCSABt7+PQeXBaIbQLOffvsDBDJ6Ynj48KHsUwAg6QTXJBPpeYwF3AbAF7gNAE3gNgA0gdsA0ARuA0ATuA0ATeA2ADSB2wDQBG4DQBO4DQBN4DYANIHbANAEbgNAE7gNxqDb7Var1f39/d3d3e3t7Tt37ty5c2djY+PGjRs3btzY2Ngwtmxvbz99+nR/f79arfZ6PdlnrShwG/hzdnbW7/d7vV53Inq9Xr/fPzs7k30dagG3AZ/BYNDr9drt9vHxcSMkms1mu93udruDwUD29dEHbgMO3W73+Pj4TWQcHx93u13ZV0kcuA1s9Hq9k5OTZiycnJxgNB4dcBsMMXrg8VjN0m63YXgUwG2gn52dtdvt6HrgQWi325hsCxe4rTq9Xk/TtPjDtRtN0xDAQwRuK02n04l0zmxcms1mp9ORXSpEgNuKMhgMTk9Pw1rcCpfT01P0z6cHbqtIv9+XPsD2pt1u9/t92eWUbuC2cgwGg1arJVtef1qtFqL3NMBttej3+5qmye50B6XVaiF6TwzcVojBYJDwrrgbrI1NDNxWiMROnnlzenoqu+RSCdxWhbdv39ZTy9u3b2WXX/qA20rQ7XabzabsADw5zWYTvy0ZF7hNn7Ozs0ajITv0Tkuj0cDAeyzgNn3a7bbsuBsO7XZbdlmmCbhNnG6320h/0DZoNBromQcHbhNH0zTZSoaJpmmySzQ1wG3KdDqdn8mBH5MEBG6Txbi3VHagDZ9Wq4XHrQUBbpPl7du3skNsVGC5OwhwmyzNZlN2iI2KZr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/qMsThOU2X9AAAAAElFTkSuQmCC" alt="" />

 1.    通过纯CSS实现。

该方法最简单,最粗暴。

这是部分HTML代码。

 <div class="myfriends" >
我的好友
<div class="myfriendsList" >
<ul>
<li><a href="">闺蜜</a></li>
<li><a href="">同学</a></li>
<li><a href="">创建分组</a></li>
</ul>
</div>
</div>

CSS代码部分(非关键部分已删除)

 .myfriends{

     overflow: hidden;

     position: relative;
width: 90px; height: 30px;/*父元素的容器高30px*/ }
.myfriends:hover { overflow: visible; }
.myfriendsList { position: absolute;/**/ width: 80px; height: 100px; top: 28px;/*子容器距离父容器一定要top<30*/ left: 9px; z-index:; }
当你修改成以下样式时,
 .myfriendsList {

     top: 28px;/*子容器距离父容器一定要top<30*/

 }
就出现下面这张可图的效果,当然你鼠标离开时,隐藏层又消失,那么这样永远也无法点击隐藏层的菜单选项。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAE1CAIAAAAZHa6PAAAVCElEQVR4nO2dPY8T2ZqAnRHc+EYbbLihk4kmu//hpo423uRGpXU3LfExxmqY1ojGTEvQXLTIiO0dYXRbloALzF1a7ArMDHfaiNFqGN1uAoaAlqY9gSNqg/rwqapzqsp22V1vnecJRkO5vnz8Puc9X11Vc0+CZ8+ench1AQSRR5PaEu4jCQIDZILAAIJBYADBIDCAYBAYQDAIDCAYBAYQDAJDSRgfDe9vr39563/fn/SdSAKBhfBoy0nQXD3T2rh+99nh2Hzc6M3jnesbrTOrTeWQncdvRsldX++0k9dYWTt7cbN7X7d/wPjw5W538+LZtRX1kN2XabelvdXv76w3Hae5vrM/5ZEWg8BC0Akcinzm2iNN2hof/u3mhRXDMSsXbv4tZphW4HD/S9/otBp9f/fymabpti7f/X6U9wJTsPWo2LKVDAILwRe4vfM63DT68Orx7a/WPFnWv3kdPeD9o621wKPbj199GE2OCZRb24p4H/il+DE++un57rUv/N2vffsxconx/s6699HKhe3d5z8djcNjtv2aI5JOEbh4EFgIGoFd13Xd8f4dz4qzt14om9/3N5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AYBAYQDAIDCAYBAYQDAIDCAaBAQSDwACCQWAAwSAwgGAQGEAwCAwgGAQGEAwCAwgGgQEEg8AAgkFgAMEgMIBgEBhAMAgMIBgEBhAMAgMIBoEBBIPAAIJBYADBIDCAYBAYQDAIDCAYBAYQDAIDCCaPJv8PEfs2tIOw7YkAAAAASUVORK5CYII=" alt="" />

那么,问题来了,我就时要做到截图的效果同时有能点击点击隐藏层的菜单选项应该怎么做呢?

我有个旁门左道的方法,放完整代码。

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title>发现</title>

    <style>

        .myfriends {

            overflow: hidden;

            position: relative;

            width: 130px;

            height: 30px; /*父元素的容器高30px*/

        }

        .myfriends:hover {

            overflow: visible;

        }

        .myfriendsList {

            position: absolute; /**/

            width: 80px;

            height: 140px; /*比原来的高多40px*/

            top: 40px; /*0<top<61 原因很简单,我用一个空白的容器为父容器和子容器左了衔接*/

            left: 9px;

            z-index: 10;

            border: solid 1px #c6c6c6;

            background-color: #f2f2f2;

        }

        .blank{display: block;

            left: 0;

            position: absolute;

            width: 100px;

            height: 30px;

            top: 30px;

        }

    </style>

</head>

<body>

<div class="myfriends">

    我的好友

    <span class="blank"></span>

    <div class="myfriendsList">

        <ul>

            <li><a href="">闺蜜</a></li>

            <li><a href="">同学</a></li>

            <li><a href="">创建分组</a></li>

        </ul>

    </div>

</div>

</body>

</html>

纯CSS

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALMAAADJCAIAAADnz5QDAAAI+klEQVR4nO2dMW7bPBiGPXToDQrkAF2NniBLh17A6OTNm4Ge4c9iwMgB7NmLN8fo1iFrk82LhwK9hS6Qf5AiieQn6pUdVFL4PDDaRKJsR3z88SNF0ZMXAItJ328ABgpmgA1mgA1mgM17NmPSRt9vcNC857MTr3vMiPOezw5mXMN7Pjt53f/3ivczZsSRzs55Pc0b5un6/HJeTyfz40v5f1h0uj63bis4zpv2tHCcT4xXdynNKLfUf8aMOM1n5zivUrV67ZV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corolPHrUJcwhhkb4Qx9W9fzm7ory22cSJZjkpN04gRA8SF8KyoaJcS2ryWMhr35Ul5BA9SVoII3OUSG8Ou1ld30SIniQtRFEU9krmI3Vy1MTZghA9SV+Imma+dY0fQsRsGpLK/tyQEMqXXHhCeBMqySF6cjNCaHfjRCQZRIie3IgQnbfweoWr9AIhenIDQpRpgTIo6VtSdkHbTQZC9CBtIZwxBrElYuZ0+NbvUPekASEsmHWdFUkLcS0QwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDCAiGyAiEUEMICIbICIRQQwgIhsgIhFBDC4t8seYNDnybdQkBWIAQIEAIECAEChAABQoAAIUCAECBACBAgBAgQAgQIAQKEAAFCgAAhQIAQIEAIECAECBACBAgBAoQAAUKAACFAgBAgQAgQIAQIEAIECAEChAABQoAAIUCAECBACBAgBAgQAgQIAQKEAAFCgAAhQIAQIEAIECAECP4DVX3GQiiR5AIAAAAASUVORK5CYII=" alt="" />

当我为.blank 加上background-color: #3273B0;样式时,实际是如上面截图所示。原因在注释里已标注。所谓的衔接,其实是:当鼠标移上我的好友时,空白容器blank就会“拖住”子容器,myfriendsList(前提是你blank的height > myfriendsList的height—父容器的height。)
 
 
2.通过JS实现。

好咯,我又放代码。

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title>发现</title>

    <style>

        .myfriends {

            position: relative;

            width: 130px;

            height: 30px; /*父元素的容器高30px*/

        }

        .myfriendsList {

            position: absolute; /**/

            width: 80px;

            height: 100px;

            top: 40px;/*建议top值不要太大*/

            left: 9px;

            z-index: 10;

            border: solid 1px #c6c6c6;

            background-color: #f2f2f2;

            display: none;

        }

    </style>

    <script>

        window.onload = function () {

            divShow('myfriendsList', 'myfriends');

        }

        function getID(id) {

            return document.getElementById(id)

        }

        function divShow(idson, idFather) {

            var idSon = getID(idson);

            var idFather = getID(idFather);

            var timer = null;

            idFather.onmousemove = show;

            idFather.onmouseout = hide;

            function show() {

                clearInterval(timer);

                idSon.style.display = "block";

            }

            function hide() {

                timer = setTimeout(function () {

                    idSon.style.display = "none"

                }, 200)

            }

        }

    </script>

</head>

<body>

<div class="myfriends" id="myfriends">

    我的好友

    <div class="myfriendsList" id="myfriendsList">

        <ul>

            <li><a href="">闺蜜</a></li>

            <li><a href="">同学</a></li>

            <li><a href="">创建分组</a></li>

        </ul>

    </div>

</div>

</body>

</html>

js实现

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJcAAADECAIAAAAd5yR3AAAHlUlEQVR4nO2dPY7aXBSGXaTIDiKxgLRWVkAzxWwApXLnDil7oEGyWADUNHQGpUsx7QcdjYtI2QUb4Cuu8f0799pmzJi8eR8hjca+NsgP5/4em+RK/n6SsT8AGQBaRIAWEaBFBGgRAVpEgBYR0BarIk2SJEmStKiuVZEm2eHa/LWpijRJi6p1W80hC+1p4ZAlwrsTj0RjXunGYnUo0sS5lpJaWbew65AlMoJoWuxIHYtuJPlXXv3XBKxz8f3t+nRtoaiOFYpEwptYBCxeD5kYBU7I3QS5pevT+XHnSzlkjvHOUHBD94uWJGlRiRb9YDO/FM1eodJV0jrVxCRCKBarIpW+65LFwg9bo5g+kWelKtJIRLE+7U7Eot0w6nZRqFGvhyxwtHGAF7LRYBNaWlamIQyL9kXS1/yQJUmSFZXcizEKSd0hfZqqSJOs6OqmKtIkzTK/QmCICgS/4CpQKmecEYrFq9cWqmJ279YJvJbRif1d0tvZWHqEatQm7KKVoH2RD1nSVLC2XRWE3ceYRmSbQa5qBTr0iIw0rO5jXSBq0Rp5+GfzLn/Iov42NMWSNMu82QdyQ7DYCBTqyBaL8vaqSJM09Yf2skXHofGJKDGEYbGW5DaD1nxqN4tWKf1diE8Q2W+o/7N7UHQpkTSTJaFrY127YB/VxFQRmwr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tFP7uoxojFDlkdtDg8p+XaiB61al8/3Ua2uNvOJtsymrfB9cX30md98byZCpdbaduIFtWz+9y7vRmL4631l/lqvtz7bZvyIcWi04thu3hj3LwbP+uwkSdYtLKKzaMYi6PmwHkWtY9I7yZyVBdosYV3x6L1dEzHotapOjjhhP/4M3RosYW+OXCuReN+qECNut4c5TxjxuKQ9MqBu1k0hg03PWKNWuar2XStuqnRxMZY00iLg+PfU+EGlt0uij+9wFh8OovuFrP+NCfhDG20OPbcjVAxepngTX/HGf5z7qaGOXB/Ec9ocSxoEQFaRIAWEaBFBGgRAVpEgBYfiL4LznpGmEd8bwdo8WHU2TQ18j2L/q7ADE58No4WH4T3kwxyfs1FP+xNReTOX9lvn1OlxUcg51CJj0CxlqvyNyk/gxZH4LyZBn83Ua1g6IjUt/CbEUmLI1uMKazZNT84bC1L1WrZLipGtBjpwtjYso/7RSOJsah4iho1ssDkL+vnxhZaVIxtsUH40T0/WK0lZfZuGp7GovBQU8+il3TDdlHxJBbFH4lubzgZi4qnsNh6D41XuG4yaVExukXV1AnTNL5aNepwa1RaHNeiMRa0tnTIYwvfMBXq3GowLY7Fo3PgIm/9kZd+QIIWyV8ELSJAiwjQIgK0iAAtIkCLCNAiArSIAC0iQIsI0CICtIgALSJAiwjQIgK0iAAtIkCLCNAiArSIAC0iQIsI0CICtIgALSJAiwjQIgK0iAAtIkCLCNAiArSIAC0iQIsI0CICtIgALSJAiwjQIgK0iAAtIkCLCNAiArSIAC0iQIsI0CICtIgALSLwP/IslKF2EthAAAAAAElFTkSuQmCC" alt="" />

   运行后如上截图显示,其实,最主要的是用了setTimeout这个定时器,我让隐藏层出现后,鼠标离开的0.2秒后隐藏层再消失,在这0.2秒里,用户自然会将鼠标移到隐藏层上,从而可以点击隐藏层的菜单选项。
   嗯,当然,记得一定要  clearInterval(timer);否则会出现很大的bug,由于篇幅的问题,我就不外扯了。
 
    好了,我总结的这两个方法实在是旁门左道,不像传统的方法那样规规矩矩。因为我觉得这两个方法古怪而有意思,才写下这篇博客。太简单的谁都会吧,写了还显得自己low。
 如果有什么错误欢迎大家批评指正,我定当立即修改,以免误导他人。
 
 
05-11 08:00