JS滑鼠移入,移出事件

來源:互聯網
上載者:User

標籤:

該事件的效果就像百度首頁的設定選項,當滑鼠移入,移出時的效果,廢話不多說了,直接上碼。

  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>百度</title>
    <style type="text/css">·····························································一下是CSS
    #wrap{
        width: 150px;height: 200px;
        /*background: rgb(211,211,211);*/
        margin: 200px auto 0px;
        text-align: center;
        position: relative;
        background: rgb(225,225,225);
    }
    a{
        color:white;
        display: inline-block;
        width: 150px;height: 20px;
        
    }

    .one{
        position: absolute;
        left: 70px;top: 14px;
        color: white;

    }
    #div1{
        width: 80px;height:81px;
        margin: 3px auto 0px;
        background: white;

    }
    #div1 a{
        display: inline-block;
        width:78px;
        height: 25px;
        color:black;
        font-size: 15px;
        line-height: 25px;
        text-decoration: none;
        position: relative;
        margin: 1px 1px;
        z-index: 1;
    }
    </style>
</head>
<body>
    <div id="wrap">·············································································HTML內容
        <a href="#" id="set">設定</a>
        <span class="one">♦</span>
        <div id="div1">
            <a href="#" class="two">搜尋設定</a>
            <a href="#" class="two">進階搜尋</a>
            <a href="#" class="two">搜尋曆史</a>
        </div>
    </div>
    <script type="text/javascript">······································································一下是JS

    var set = document.getElementById(‘set‘);
    var div1 = document.getElementById(‘div1‘);
    var one = document.getElementsByClassName(‘one‘);
    var two = document.getElementsByClassName(‘two‘);
    one[0].style.display = ‘none‘;
    div1.style.display = ‘none‘;
    set.onmouseover = function (){
        one[0].style.display = ‘block‘;
        div1.style.display = ‘block‘;
    }
    set.onmouseout = function (){
        one[0].style.display = ‘none‘;
        div1.style.display = ‘none‘;
    }
    two[0].onmouseover = function(){
        two[0].style.background = ‘rgb(57,139,251)‘;
    }
    two[1].onmouseover = function(){
        two[1].style.background = ‘rgb(57,139,251)‘;
    }
    two[2].onmouseover = function(){
        two[2].style.background = ‘rgb(57,139,251)‘;
    }
    two[0].onmouseout = function(){
        two[0].style.background = ‘white‘;
    }
    two[1].onmouseout = function(){
        two[1].style.background = ‘white‘;
    }
    two[2].onmouseout = function(){
        two[2].style.background = ‘white‘;
    }

    div1.onmouseover = function(){
        one[0].style.display = ‘block‘;
        div1.style.display = ‘block‘;
    }
    div1.onmouseout = function(){
        one[0].style.display = ‘none‘;
        div1.style.display = ‘none‘;
    }
    one[0].onmouseover = function(){
        one[0].style.display = ‘block‘;
        div1.style.display = ‘block‘;
    }
    one[0].onmouseout = function(){
        one[0].style.display = ‘none‘;
        div1.style.display = ‘none‘;
    }
    </script>
</body>
</html>

進入頁面時的效果是這樣的:

當滑鼠移入設定上時,效果是這樣的:

當滑鼠移入下面的選項的時候,背景顏色會變成藍色:

 

到滑鼠移出設定或下面的3個選項時,頁面就如第一張圖所示。

 

JS滑鼠移入,移出事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.