JSFiddle - React, Tailwind, and code Playground
by carlhong
HTML
<div class="main">
<div class="form">
<div class="wrapper">
<ul>
<li>
<div class="label">
<div class="location">
<div class="btn">
show picker
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<div class="header">
I am header
</div>
CSS
* {
box-sizing: border-box;
}
body {
background: #f5f7fa;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0;
}
.main {
position: relative;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
}
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
padding-left: .5rem;
user-select: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 0.75rem;
color: #1f2d3d;
font-weight: normal;
text-align: left;
background: #ffffff;
height: 2.5rem;
line-height: 2.5rem;
}
.form {
top: 2.5rem;
position: absolute;
overflow-x: hidden;
width: 100%;
color: #1f2d3d;
padding: 0.25rem 0.55rem 2.5rem;
padding-bottom: 0.25rem;
left: 0;
right: 0;
bottom: 0;
}
.wrapper {
bottom: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
overflow: auto;
padding: 0.25rem 0.55rem;
-webkit-overflow-scrolling: touch;
}
ul {
margin: 0;
padding: 0;
}
li {
padding: 0.3rem 0;
list-style-type: none;
}
.location {
position: relative;
/* overflow: hidden; */
}
.btn {
text-align: center;
color: #248af9;
margin-top: 0.5rem;
width: 100%;
height: 2rem;
line-height: 2rem;
background-color: #ffffff;
border: 1px dashed #e5e5e5;
}
.picker {
z-index: 100;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #ffffff;
}
.bar {
height: 2.2rem;
}
.picker-cancel {
color: #248af9;
line-height: 2rem;
position: absolute;
top: 0;
left: 0;
width: 3rem;
height: 2.2rem;
border: none;
margin: 0;
padding: 0;
outline: none;
background-color: #ffffff;
}
.picker-ok {
color: #248af9;
line-height: 2rem;
position: absolute;
top: 0;
right: 0;
width: 3rem;
height: 2.2rem;
border: none;
margin: 0;
padding: 0;
outline: none;
background-color: #ffffff;
}
.location-search {
position: absolute;
top: 0.2rem;
left: 3rem;
right: 3rem;
line-height: 1.4rem;
}
.section {
...
JavaScript
var $picker = $("<div class=\"picker\">" +
"<div class=\"bar\">" +
"<button class=\"picker-cancel\">取消</button>" +
"<button class=\"picker-ok\">确定</button>" +
"<input class=\"location-search\" id=\"tip-input\" placeholder=\"搜索\">" +
"</div>" +
"<div class=\"section\"></div>" +
"</div>");
$(".btn").click(function() {
$picker.appendTo($(".location"));
$(".picker-cancel").click(function() {
$picker.detach();
});
});