JavaScript實現百度搜尋網頁面

來源:互聯網
上載者:User

標籤:css   charset   oat   eps   hit   text   cti   osi   pre   

JavaScript實現百度搜尋網頁面

HTML

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>百度一下,你就知道</title>        <!--引入百度icon小表徵圖-->        <link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon"/>        <link rel="stylesheet" href="css/baidu.css">    </head>    <body>        <div class="bj">            <div class="logo_d">                <img src="img/logo.png" class="logo">            </div>            <div class="bd_k">                <input type="text" id="input">                <i class="iconfont">&#xe652;</i>                <button id="btn">百度一下</button>            </div>            <!--ul li-->            <div class="ul_d">                <ul id="ul" style="display:none;">                    <li class="li"></li>                    <li class="li"></li>                    <li class="li"></li>                </ul>            </div>        </div>        <!--滑鼠跟隨-->        <div id="to_top"></div>        <script type="text/javascript" src="js/baidu.js"></script>    </body></html>

CSS

/*引線上icon小表徵圖*/@font-face {  font-family: ‘iconfont‘;  /* project id 548708 */  src: url(‘http://at.alicdn.com/t/font_548708_l4m75bgmnyaatt9.eot‘);  src: url(‘http://at.alicdn.com/t/font_548708_l4m75bgmnyaatt9.eot?#iefix‘) format(‘embedded-opentype‘),  url(‘http://at.alicdn.com/t/font_548708_l4m75bgmnyaatt9.woff‘) format(‘woff‘),  url(‘http://at.alicdn.com/t/font_548708_l4m75bgmnyaatt9.ttf‘) format(‘truetype‘),  url(‘http://at.alicdn.com/t/font_548708_l4m75bgmnyaatt9.svg#iconfont‘) format(‘svg‘);}i{    font-family: ‘iconfont‘;    /*去掉表徵圖的預設樣式(斜體)*/    font-style: normal;}.iconfont{    font-family: ‘iconfont‘;    font-size: 23px;    color: gray;    position:absolute;    top:184px;    right:493px;}.iconfont:hover{    color: deepskyblue;    cursor:pointer;}*{    margin:0;    padding:0;}body,html{    width:100%;    overflow:hidden;}/*滑鼠跟隨*/#to_top{        position:absolute;        cursor:pointer;        width: 35px;        height: 30px;        background-image: url(../img/貓.png);        background-size:100% 100%;}/*背景*/.bj{    width:100%;    height:768px;    /*background-color:red;*/    background-image: url(../img/1F613111001-4.jpg);    /*設定背景圖片透明度*/    opacity:0.8;    background-size:100% 100%;    overflow:hidden;}/*內容*/.logo_d{    width:260px;    height:125px;    /*background-color:red;*/    margin:0px auto;    margin-top:40px;    margin-bottom:10px;}.logo{    height:125px;}.bd_k{    width:650px;    height:42px;    /*background-color:yellow;*/    margin:0 auto;}#input{    width:521px;    height:38px;    outline:none;    font-size:16px;    text-indent:8px;    float:left;}#btn{    width:125px;    height:42px;    background-color:deepskyblue;    border:1px solid deepskyblue;    float:right;    font-size:18px;    color:white;    outline:none;    cursor:pointer;}#btn:hover{    background-color:dodgerblue;    border:1px solid dodgerblue;}.ul_d{    width:649px;    height:120px;    /*background-color:yellow;*/    margin:0 auto;    }#ul{    list-style:none;    width:521px;    /*background-color:red;*/    border:1px solid #ededed;    margin-top:-2px;}#ul li{    line-height:32px;    text-indent:8px;}#ul li:hover{    background-color:rgba(30,144,255,0.6);    cursor:pointer;}

JS

var btn=document.getElementById("btn");var ipt=document.getElementById("input");//擷取每個li作為一個數組var arr=document.getElementsByTagName("li");//點擊事件btn.onclick=function(){    //擷取ul的id,並且修改它的屬性.(顯示)    var ul=document.getElementById("ul");    ul.setAttribute("style","display:block;");    //給下拉input傳值    for(var i=arr.length-1;i>=0;i--){        if(i==0){            arr[i].innerText=document.getElementById("input").value;        }else{            arr[i].innerText=arr[i-1].innerText;        }    }}//鍵盤彈起發生事件//ipt.onkeyup=function(){//    //擷取ul的id,並且修改它的屬性.(顯示)//    var ul=document.getElementById("ul");//    ul.setAttribute("style","display:block;");//    //給下拉input傳值//    for(var i=arr.length-1;i>=0;i--){//        if(i==0){//            arr[i].innerText=document.getElementById("input").value;//        }else{//            arr[i].innerText=arr[i-1].innerText;//        }//    }//}//input擷取焦時間點事件ipt.onfocus=function(){    var ul=document.getElementById("ul");    ul.setAttribute("style","display:block;");}//input失去焦時間點事件ipt.onblur=function(){    var ul=document.getElementById("ul");    ul.setAttribute("style","display:none;");}//滑鼠li所選中的下拉值再賦值給inputfor(var x of arr){    x.onmousedown=zhi;}function zhi(){    ipt.value=this.innerText;}//滑鼠跟隨window.onload = function(){     var oTop = document.getElementById("to_top");     document.onmousemove = function(evt){      var oEvent = evt || window.event;      var scrollleft = document.documentElement.scrollLeft || document.body.scrollLeft;      var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;      oTop.style.left = oEvent.clientX + scrollleft +10 +"px";      oTop.style.top = oEvent.clientY + scrolltop + 10 + "px"; }} 

JavaScript實現百度搜尋網頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.