您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍HTML5和jQuery如何实现弹出创意搜索框,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
本效果适用于移动设备,可以使用手机等浏览效果。
HTML代码如下:
<!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的代码如下:
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();
}以上是HTML5和jQuery如何实现弹出创意搜索框的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。