首页 何问起 前端特效 htbtn-4 闪电 使用方法

jQuery+HTML5弹出创意搜索框层

效果体验:http://hovertree.com/texiao/jquery/26/

本效果适用于移动设备,可以使用手机等浏览效果。

代码下载:http://hovertree.com/h/bjaf/e14uccpw.htm

HTML代码如下:

 1 <!doctype html>
 2 <html lang="zh">
 3 <head>
 4 <meta charset="UTF-8">
 5 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 6 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
 7 <title>jQuery+CSS3创意搜索框特效 - 何问起</title>
 8 <link rel="stylesheet" type="text/css" href="http://hovertree.com/texiao/jquery/26/css/default.css" />
 9 <!--必要样式-->
10 <link rel="stylesheet" type="text/css" href="http://hovertree.com/texiao/jquery/26/css/search-form.css" />
11 
12 </head>
13 <body>
14 <div>
15 <a href="http://hovertree.com/">首页</a> <a href="http://hovertree.com/texiao/">特效</a> <a href="http://hovertree.com/h/bjaf/sousuokuang.htm">原文</a>
16 </div>
17 <form onSubmit="submitFn(this, event);" name="yestop">
18 <div class="search-wrapper">
19 <div class="input-holder">
20 <input type="text" class="search-input" placeholder="请输入关键词" name="hewenqi" />
21 <input type="hidden" name="q" />
22 <button class="search-icon" onClick="searchToggle(this, event);"><span></span></button>
23 </div>
24 <span class="close" onClick="searchToggle(this, event);"></span>
25 <div class="result-container">
26 
27 </div>
28 </div>
29 </form>
30 
31 <script src="http://hovertree.com/ziyuan/jquery/jquery-1.12.0.min.js" type="text/javascript"></script>
32 <script type="text/javascript" src="http://hovertree.com/texiao/jquery/26/js/hovertreesearch.js"></script>
33 </body>
34 </html>

 

其中hovertreesearch.js的代码如下:

 1 function searchToggle(obj, evt) {
 2 var container = $(obj).closest('.search-wrapper');
 3 
 4 if (!container.hasClass('active')) {
 5 container.addClass('active');
 6 evt.preventDefault();
 7 }
 8 else if (container.hasClass('active') && $(obj).closest('.input-holder').length == 0) {
 9 container.removeClass('active');
10 // clear input
11 container.find('.search-input').val('');
12 // clear and hide result container when we press close
13 container.find('.result-container').fadeOut(100, function () { $(this).empty(); });
14 }
15 }
16 
17 function submitFn(obj, evt) {
18 var value = $(obj).find('.search-input').val().trim();
19 
20 var _html = "您搜索的关键词: ";
21 if (!value.length) {
22 _html = "关键词不能为空。";
23 }
24 else {
25 window.open("http://cn.bi" + "ng.com/search?q=site%3Ahove" + "rtree.com " + value + "&hewenqi=yestop");
26 _html += "<b>" + value + "</b>";
27 }
28 
29 $(obj).find('.result-container').html('<span>' + _html + '</span>');
30 $(obj).find('.result-container').fadeIn(100);
31 
32 evt.preventDefault();
33 }

更多特效:http://www.cnblogs.com/roucheng/p/texiao.html

posted @ 2016-01-28 23:00  roucheng  阅读(9273)  评论(0编辑  收藏  举报