如何创建像Facebook或WhatsApp这样的搜索框? (移动)

时间:2015-02-11 15:54:31

标签: angularjs css3 user-interface user-experience

有没有办法手动执行此操作?我尝试使用Ionic Framework,他们有attribute,但现在已弃用。

通过Facebook&WhatsApp的搜索框我的意思是:

1 - 在第一次叹息时隐藏

2 - 如果你想看到它,你必须下拉

3 - 一旦你专注于它,它会一直延伸到屏幕顶部并重叠标题

4 - 有一个用于删除搜索框内容的X按钮和名为&#34的其他按钮;取消"关闭搜索框。

非常确定每个人都已经注意到这种行为。

那么,实现它的技术是什么?

我正在使用Angular,所以我不知道是否有办法做一个指令,或者只是用css?你有什么建议吗?

enter image description here enter image description here

something like this

1 个答案:

答案 0 :(得分:1)

让我意识到这一切对我来说太费时间了。但如果你熟悉"那就不那么困难了。过渡"在css3。

这是" lite版本"



var searchbox={
	topPos_open:0, topPos_close:-50, isOpen:false,
	open:function(){
	    var box=document.getElementById("searchbox");
	    box.style.top=this.topPos_open+"px";
        document.getElementById("searchfield").focus();
        this.isOpen=true;
	},
	close:function(){
	    var box=document.getElementById("searchbox");
	    box.style.top=this.topPos_close+"px";
	    this.isOpen=false;
	},
	pop:function(){
	    !this.isOpen?this.open():this.close();
	},
	clear:function(){
		document.getElementById("searchfield").value="";
	}
}

#searchbox{position:fixed; top:-50px; left:0px; width:100%; height:60px; background-color:rgba(135, 206, 235, 1); -webkit-transition:top 0.5s ease 0s; -moz-transition:top 0.5s ease 0s; transition:top 0.5s ease 0s;}
#searchbox input{border:0px none; margin:0px 10px 0px 10px; padding:0px; width:80%; font-size:20px;}
#searchbox #input{float:left; background-color:rgba(255, 255, 255, 1); border:1px solid #dddddd; border-radius:20px; margin:5px; padding:5px; width:70%; min-width:250px;}
#searchbox #close{float:right; padding:10px:}
#searchbox button{border:0px none; background-color:transparent; font-size:20px; cursor:pointer;}
#searchbox #dots{clear:both; text-align:center; font-size:25px; cursor:pointer;}

<div id="searchbox">
    <div id="input">
      <input type="text" id="searchfield" value="">
      <button type="button" onclick="searchbox.clear()">
        X
      </button>
    </div>
    <div id="close">
      <button type="button" onclick="searchbox.close()">
        Cancel
      </button></div>
    <div id="dots" onclick="searchbox.pop()">
      ......
    </div>
</div>


<br>
<br>
<br>
<br>
Click the dots 
&#13;
&#13;
&#13;