Home > Web Front-end > H5 Tutorial > How to implement pop-up creative search box layer with HTML5 and jQuery

How to implement pop-up creative search box layer with HTML5 and jQuery

不言
Release: 2018-06-25 10:42:41
Original
2759 people have browsed it

This article mainly shares the example code of jQuery and HTML5 pop-up creative search box layer. It has a certain reference value, let’s take a look at it

This effect is suitable for mobile devices, and you can use mobile phones to browse the effect.

HTML code is as follows:

<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>jQuery+CSS3创意搜索框特效 - 何问起</title>
<link rel="stylesheet" type="text/css" href="http://hovertree.com/texiao/jquery/26/css/default.css" />
<!--必要样式-->
<link rel="stylesheet" type="text/css" href="http://hovertree.com/texiao/jquery/26/css/search-form.css" />

</head>
<body>
<p>
<a href="http://hovertree.com/">首页</a> <a href="http://hovertree.com/texiao/">特效</a> <a href="http://hovertree.com/h/bjaf/sousuokuang.htm">原文</a>
</p>
<form onSubmit="submitFn(this, event);" name="yestop">
<p class="search-wrapper">
<p class="input-holder">
<input type="text" class="search-input" placeholder="请输入关键词" name="hewenqi" />
<input type="hidden" name="q" />
<button class="search-icon" onClick="searchToggle(this, event);"><span></span></button>
</p>
<span class="close" onClick="searchToggle(this, event);"></span>
<p class="result-container">
</p>
</p>
</form>
<script src="http://hovertree.com/ziyuan/jquery/jquery-1.12.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://hovertree.com/texiao/jquery/26/js/hovertreesearch.js"></script>
</body>
</html>
Copy after login

The code of hovertreesearch.js is as follows:

function searchToggle(obj, evt) {
var container = $(obj).closest(&#39;.search-wrapper&#39;);
if (!container.hasClass(&#39;active&#39;)) {
container.addClass(&#39;active&#39;);
evt.preventDefault();
}
else if (container.hasClass(&#39;active&#39;) && $(obj).closest(&#39;.input-holder&#39;).length == 0) {
container.removeClass(&#39;active&#39;);
// clear input
container.find(&#39;.search-input&#39;).val(&#39;&#39;);
// clear and hide result container when we press close
container.find(&#39;.result-container&#39;).fadeOut(100, function () { $(this).empty(); });
}
}
function submitFn(obj, evt) {
var value = $(obj).find(&#39;.search-input&#39;).val().trim();
var _html = "您搜索的关键词: ";
if (!value.length) {
_html = "关键词不能为空。";
}
else {
window.open("http://cn.bi" + "ng.com/search?q=site%3Ahove" + "rtree.com " + value + "&hewenqi=yestop");
_html += "<b>" + value + "</b>";
}
$(obj).find(&#39;.result-container&#39;).html(&#39;<span>&#39; + _html + &#39;</span>&#39;);
$(obj).find(&#39;.result-container&#39;).fadeIn(100);
evt.preventDefault();
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's learning, more Please pay attention to the PHP Chinese website for related content!

Related recommendations:

html5 canvas and JavaScript how to implement local screenshots

html5 and css3 and jquery implement music player

The above is the detailed content of How to implement pop-up creative search box layer with HTML5 and jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template