我们知道wordpress 官方主题采用了H5,还有就是那个弹性的搜索框非常好看,我就来说说怎么么用JQuery和CSS 来实习wordpress弹性搜索框,官方是用css实现的,但在IE内核下显示就不好了,用JQuery 来做就可以兼容主流浏览器。
css版我就直接贴上代码吧供大家参考
1
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
1
| <html xmlns="http://www.w3.org/1999/xhtml">
|
1
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
1
| <title>wordpress CSS搜索伸缩菜单</title>
|
1
| border-color:#CCC #EEE #EEE #CCC;
|
1
| -webkit-border-radius:4px;
|
1
| -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| background-color:#fafafa;
|
1
| behavior:url(/wp-content/themes/EchoWeb/lib/PIE.htc);
|
1
| -moz-transition:all linear .5s;
|
1
| -webkit-transition:all linear .5s;
|
1
| -o-transition:all linear .5s;
|
1
| transition:all linear .5s
|
1
| input:hover, select:hover, textarea:hover {
|
1
| border-color: rgba(82, 168, 236, .75);
|
1
| box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| -moz-box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| -webkit-box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| clip: rect(1px, 1px, 1px, 1px);
|
1
| position: absolute !important;
|
1
| -moz-transition-duration: 400ms;
|
1
| -moz-transition-property: width, background;
|
1
| -moz-transition-timing-function: ease;
|
1
| background: url(img/search.png) no-repeat scroll 5px 6px transparent;
|
1
| border-radius: 2px 2px 2px 2px;
|
1
| padding: 4px 10px 4px 28px;
|
1
| -webkit-transition-duration: 400ms;
|
1
| -webkit-transition-property: width, background;
|
1
| -webkit-transition-timing-function: ease;
|
1
| -moz-transition-duration: 400ms;
|
1
| -moz-transition-property: width, background;
|
1
| -moz-transition-timing-function: ease;
|
1
| -o-transition-duration: 400ms;
|
1
| -o-transition-property: width, background;
|
1
| -o-transition-timing-function: ease;
|
1
| background-color: #f9f9f9;
|
1
| <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
|
1
| <label for="s" class="assistive-text">
|
1
| <?php _e( 'Search' ); ?>
|
1
| <input type="text" class="field" id="s" name="s" value="<?php the_search_query(); ?>" placeholder="关键字" required="required" autofocus="autofocus">
|
1
| <input type="submit" class="submit" name="submit" id="searchsubmit" value="Search">
|
jquery也直接贴上代码
1
| <;meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
1
| <;title>wordpress 弹性搜索框</title>
|
1
| <;script type="text/javascript" src="js/jquery.min.js"></script>
|
1
| border-color:#CCC #EEE #EEE #CCC;
|
1
| -webkit-border-radius:4px;
|
1
| -moz-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 0 rgba(255, 255, 255, 0.2);
|
1
| background-color:#fafafa;
|
1
| behavior:url(/wp-content/themes/EchoWeb/lib/PIE.htc);
|
1
| -moz-transition:all linear .5s;
|
1
| -webkit-transition:all linear .5s;
|
1
| -o-transition:all linear .5s;
|
1
| transition:all linear .5s
|
1
| input:hover, select:hover, textarea:hover {
|
1
| border-color: rgba(82, 168, 236, .75);
|
1
| box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| -moz-box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| -webkit-box-shadow: 0 0 8px rgba(82, 168, 236, .5);
|
1
| clip: rect(1px, 1px, 1px, 1px);
|
1
| position: absolute !important;
|
1
| -moz-transition-duration: 400ms;
|
1
| -moz-transition-property: width, background;
|
1
| -moz-transition-timing-function: ease;
|
1
| background: url(img/search.png) no-repeat scroll 5px 6px transparent;
|
1
| border-radius: 2px 2px 2px 2px;
|
1
| padding: 4px 10px 4px 28px;
|
1
| -webkit-transition-duration: 400ms;
|
1
| -webkit-transition-property: width, background;
|
1
| -webkit-transition-timing-function: ease;
|
1
| -moz-transition-duration: 400ms;
|
1
| -moz-transition-property: width, background;
|
1
| -moz-transition-timing-function: ease;
|
1
| -o-transition-duration: 400ms;
|
1
| -o-transition-property: width, background;
|
1
| -o-transition-timing-function: ease;
|
1
| <;script type="text/javascript">
|
1
| $(document).ready(function(){
|
1
| $(".field").focus(function(){
|
1
| $(this).stop(true,false).animate({width:"175px"},"slow");
|
1
| $(this).animate({width:"72px"},"slow");
|
1
| <;form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
|
1
| <;label for="s" class="assistive-text"></label>
|
1
| <;input type="text" class="field" id="s" name="s" value="<?php the_search_query(); ?>" placeholder="关键字" required="required" autofocus="autofocus">
|
1
| <;input type="submit" class="submit" name="submit" id="searchsubmit" value="Search">
|
代码例子下载CSS版 JQuery 版