JavaScript implementation Baidu Search page
Html
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title>Baidu a bit, you will know</title> <!--introduction of Baidu icon Small icons - <Linkrel= "shortcut icon"href= "Https://www.baidu.com/favicon.ico"type= "Image/x-icon"/> <Linkrel= "stylesheet"href= "Css/baidu.css"> </Head> <Body> <Divclass= "BJ"> <Divclass= "Logo_d"> <imgsrc= "Img/logo.png"class= "logo"> </Div> <Divclass= "Bd_k"> <inputtype= "text"ID= "Input"> <Iclass= "Iconfont">& #xe652;</I> <ButtonID= "BTN">Baidu a bit</Button> </Div> <!--ul Li - <Divclass= "Ul_d"> <ulID= "ul"style= "Display:none;"> <Liclass= "Li"></Li> <Liclass= "Li"></Li> <Liclass= "Li"></Li> </ul> </Div> </Div> <!--Mouse Follow - <DivID= "To_top"></Div> <Scripttype= "Text/javascript"src= "Js/baidu.js"></Script> </Body></HTML>
Css
/* Lead online icon Small icons */@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 '; /* Remove the icon's default style (italic) */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;} /* Mouse Follow */#to_top {position:absolute; Cursor:pointer; width:35px; height:30px; Background-image:url (.. /img/Cat. png); Background-size:100% 100%;} /* Background */.bj{width:100%; height:768px; /*background-color:red;*/Background-image:url (.. /img/1f613111001-4.jpg); /* Set Background image transparency */opacity:0.8; background-size:100% 100%; Overflow:hidden;} /* content */.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");//Get each Li as an array var arr= document.getElementsByTagName ("Li");//click event Btn.onclick=function () {//Get the ID of UL and modify its properties. Display) var Ul=document.getelementbyid ("ul"); Ul.setattribute ("Style", "display:block;"); Give the drop-down input value 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; }}//Keyboard Bounce event occurs//ipt.onkeyup=function () {//////Get the ID of UL and modify its properties. ( Display)//var Ul=document.getelementbyid ("ul");//Ul.setattribute ("style", "display:block;"); ////Drop input value//for (Var i=arr.length-1;i>=0;i--) {//if (i==0) {//Arr[i].innertext=document.gete Lementbyid ("Input"). value;//}else{//arr[i].innertext=arr[i-1].innertext;//}//}//}//input get Focus Event Ipt.onfocus=function () {var Ul=document.getelementbyid ("ul"); Ul.setattribute ("style", "dispLay:block; ");} Input loses focus event ipt.onblur=function () {var Ul=document.getelementbyid ("ul"); Ul.setattribute ("Style", "display:none;"); The drop-down value selected by the mouse Li is then assigned to Inputfor (var x of arr) {X.onmousedown=zhi;} function Zhi () {ipt.value=this.innertext;} Mouse follows 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 + + "px"; }}
JavaScript implementation Baidu Search page