HTML5和jQuery实现弹出创意搜索框层的方法


本文摘自PHP中文网,作者不言,侵删。

本文主要分享了jQuery和HTML5弹出创意搜索框层的实例代码。具有一定的参考价值,下面一起来看下吧

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

HTML代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

<!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>

其中hovertreesearch.js的代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

function searchToggle(obj, evt) {

var container = $(obj).closest('.search-wrapper');

if (!container.hasClass('active')) {

container.addClass('active');

evt.preventDefault();

}

else if (container.hasClass('active') && $(obj).closest('.input-holder').length == 0) {

container.removeClass('active');

// clear input

container.find('.search-input').val('');

// clear and hide result container when we press close

container.find('.result-container').fadeOut(100, function () { $(this).empty(); });

}

}

function submitFn(obj, evt) {

var value = $(obj).find('.search-input').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('.result-container').html('<span>' + _html + '</span>');

$(obj).find('.result-container').fadeIn(100);

evt.preventDefault();

}

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

html5 canvas和JavaScript如何实现本地截图

html5和css3以及jquery实现音乐播放器

以上就是HTML5和jQuery实现弹出创意搜索框层的方法的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

javascript jQuery是什么

jQuery attr与css区别是什么

jQuery变量加$和不加$的区别是什么

jQuery给元素设置/取消readonly和disabled属性

jQuery如何显示和隐藏元素

jQuery 如何判断iframe是否加载完成

jQuery怎么判断元素是否被点击

jQuery怎么判断id是否存在

jQuery $(document).ready()和onload的区别是什么

jQuery和zepto是什么?

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...