How to implement imitating Sina Weibo search box using JS CSS
This article mainly introduces the method of implementing JS CSS to imitate the Sina Weibo search box. It analyzes the javascript control skills for the search box style with examples. It has certain reference value. Friends in need can refer to it
The example in this article describes the method of implementing a Sina Weibo-like search box using JS CSS. Share it with everyone for your reference. The specific implementation method is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title>JS+CSS仿类似新浪微博搜索框的效果</title> <style type="text/css"> * { padding:0; margin:0;} body { font-size:14px; } #box { width:600px; margin:40px auto;} #in { width:240px; height:24px; line-height:24px; border:1px solid #369; border-radius:4px; box-shadow:inset 0 0 2px #999; } #suggest { display:none; position:relative; margin-top:-1px; width:240px; padding-top:1px; border:1px solid #369; border-top:0 none; border-radius:4px; box-shadow:inset 0 0 2px #999; overflow:hidden; } #suggest a { display:block; color:#f00; height:24px; line-height:24px; text-decoration:none; padding:0 4px;} #suggest a:hover { background:#eee;} #suggest a span { color#369;} </style> <script type="text/javascript"> window.onload=function(){ //声明一坨变量供下面使用 var obox=document.getElementById("box"); obj=document.getElementById("in"); osug=document.getElementById("suggest"); oa=osug.getElementsByTagName("span"); //兼容ie和火狐浏览器的方式,但是经测试发现ie678可以ie9却不行在删除的时候无法触发,网上查下说有ie9这个问题 obj.oninput=obj.onpropertychange=onchange; function onchange(){ var txt=this.value; var words=txt.length; if(words==0){ osug.style.display="none"; }else if(words<=8){ osug.style.display="block"; for( var i=0;len=oa.length,i<len;i++){ oa[i].innerHTML=txt; } }else if(words>8){ osug.style.display="block"; var limit=txt.substring(0,8)+"..."; for( var i=0;len=oa.length,i<len;i++){ oa[i].innerHTML=limit; } } } } function disbox(){ document.getElementById("suggest").style.display="none"; } </script> </head> <body> <dl id="box"> <dt><input onblur="disbox()" type="text" name="" id="in" /></dt> <dd id="suggest" > <a href="###">搜“<span></span>”相关微博</a> <a href="###">搜“<span></span>”相关用户</a> </dd> </dl> </body> </html>
Related recommended downloads:
jQuery CSS3 animated expansion and contraction search box special effects
Jquery implements search box special effects that can be displayed and closed
Pure javaScript implementation of imitating Baidu search box association word prompt code
The above is the entire content of this chapter. For more related tutorials, please visit JavaScript Video Tutorial!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
