以带网格的形式过渡
Transition in a form with grid
我正在尝试创建一个网格形式,其中应该有两个区域可以通过单击“容器”和“名称”之后的 ([...]) 来显示。
为此,必须使用过渡更改高度和底部边距。
不幸的是,我无法创建平滑的运动。
但是自己找:
function validateForm() {
var url_input = document.getElementById("url_input");
var name_input = document.getElementById("name_input");
if (name_input.value == "" && url_input.value !== "") {
name_input.placeholder = "bitte eintragen";
return false;
} else {
return true;
}
}
document
.getElementById("container_select")
.addEventListener("change", fill_input);
function fill_input() {
// get selected value from pulldown
var select_value = document.getElementById("container_select").value;
// set input value with pulldown value
document.getElementById("container_input").value = select_value;
console.log("select_value " + select_value);
}
select {
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: "";
} /* HIDE ARROW FROM DOPDOWN */
select::-ms-expand {
display: none;
} /* HIDE ARROW FROM DOPDOWN */
.hidden {
display: none;
}
.font_brighter:hover {
filter: brightness(150%);
}
@media (prefers-color-scheme: dark) {
:root {
--darkest_grey: #1e1e1e;
--dark_grey: #333333;
--white: #e0e0e0;
--black: #000;
--red: rgb(114, 0, 0);
--lightred: #ff5458;
--grey: rgb(130, 130, 130);
}
}
* {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
*:focus {
outline: none;
}
body {
background: #1e1e1e;
padding: 30px;
}
fieldset {
width: 350px;
margin: 0;
padding: 15px 20px 10px 12px;
border-radius: 5px;
}
legend {
font-size: 1.4em;
color: var(--white);
}
.new_entry {
width: 350px;
display: grid;
grid-template-areas: "container submit " "position color" "hr hr" "name url" "user password" "post_data post_data" "notes notes";
grid-template-columns: 50% 50%;
grid-template-rows: auto auto auto auto;
grid-gap: 0em 0.5em;
background: var(--darkest_grey);
color: var(--white); /* padding: 1.2em; */
}
textarea:focus,
input[type="text"]:focus,
select:focus,
button:focus {
background: #444 !important;
}
.new_entry textarea {
height: calc(100% - 1.5em);
resize: none;
}
.new_entry button {
padding: 0.5em 0 0.5em 0;
}
.new_entry button:hover {
filter: brightness(120%);
}
.new_entry input:not([type="radio"]):not([type="checkbox"]),
.new_entry textarea,
.new_entry select,
.new_entry button {
width: 100%;
border: solid 1px var(--black);
background: var(--dark_grey);
border-radius: 3px;
color: lightslategray;
padding: 0.2em;
line-height: 1.5em;
}
.new_entry label {
display: inline;
padding-left: 0.5em;
font-family: serif;
}
/* DISPLAY NONE */
/*
.new_entry>div {margin-bottom: .8em;}
#container {grid-area: container;}
#delete {grid-area: delete;}
#delete>label {display: inline;}
#position {grid-area: position; display: none; }
#color {grid-area: color; display: none;}
#name {grid-area: name;}
#url {grid-area: url;}
#hr {grid-area: hr; height: 1px; background:var(--grey); display: none;}
#container_extra:checked~#color,#container_extra:checked~#position,#container_extra:checked~#hr, #item_extra:checked~#password, #item_extra:checked~#post_data, #item_extra:checked~#user, #item_extra:checked~#notes {display: inline;}
#container_extra:checked~ #container label.checkbox_del, #item_extra:checked~#name label.checkbox_del {display: inline;}
label.checkbox_del {display: none;}
#user {grid-area: user;display: none;}
#password {grid-area: password;display: none;}
#notes {grid-area: notes;display: none;}
#post_data {grid-area: post_data;display: none;}
#submit {grid-area: submit; }
*/
/* DISPLAY NONE */
/* TRANSITION */
.new_entry > div {
margin-bottom: 0.8em;
background: var(--darkest_grey);
}
#container {
grid-area: container;
}
#submit {
grid-area: submit;
}
#position {
grid-area: position;
}
#color {
grid-area: color;
}
#hr {
grid-area: hr;
height: 1px;
background: var(--grey);
}
#name {
grid-area: name;
}
#url {
grid-area: url;
}
#user {
grid-area: user;
}
#password {
grid-area: password;
}
#notes {
grid-area: notes;
}
#post_data {
grid-area: post_data;
}
#color,
#position,
#hr,
#password,
#post_data,
#user,
#notes {
margin-bottom: 0em;
overflow: hidden;
max-height: 0;
transition: max-height 0.6s linear, margin-bottom 0.4s linear;
/* transition: margin-bottom 2s;
transition: max-height 1s; */
/* transition:
max-height 0.8s linear,
margin-bottom 0.4s linear; */
}
#container_extra:checked ~ #color,
#container_extra:checked ~ #position,
#container_extra:checked ~ #hr,
#item_extra:checked ~ #password,
#item_extra:checked ~ #post_data,
#item_extra:checked ~ #user,
#item_extra:checked ~ #notes {
margin-bottom: 0.8em;
max-height: 1000px;
/* transition: max-height 0.3s ease-out 0.5s, margin-bottom 1.3s ease; */
transition: max-height 1s linear, margin-bottom 0.2s linear;
}
label.checkbox_del {
visibility: hidden;
transition: visible 1.5s;
}
#container_extra:checked ~ #container label.checkbox_del,
#item_extra:checked ~ #name label.checkbox_del {
visibility: visible;
transition: visible 1.5s;
}
/* TRANSITION */
#submit button {
width: 50%;
margin-top: 1.4em;
float: right;
color: var(--white);
}
.icon_more {
color: var(--grey);
font-size: 50%;
position: relative;
top: -1px;
left: 2px;
cursor: pointer;
}
.icon_del {
position: relative;
right: 0px;
top: 3px;
height: 12px;
width: 12px;
margin: 0;
}
.new_entry input::placeholder {
color: #ff2727;
}
.new_entry input[type="checkbox"] {
border: solid 1px var(--black);
background: var(--red);
border-radius: 3px;
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
transition-duration: 0.5s;
}
.new_entry input[type="checkbox"]:checked {
background-color: var(--lightred);
}
#container > input {
width: 82%;
}
#container > select {
width: 27.2px;
padding: 0.2em 0.2em 0.2em 0;
}
#container_select {
color: transparent;
}
#container_select option {
color: var(--white);
}
.dropdown {
display: inline;
background-repeat: no-repeat, repeat;
background-size: 20px 20px;
height: 20px;
width: 20px;
z-index: 55;
position: absolute;
cursor: pointer;
pointer-events: none;
margin: 6px 0 0 6px;
background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" fill="%23E0E0E0" viewBox="0 0 30 30"><path d="M 0 8 l 2 -3 l 9 9.33 l 8 -9.33 l 2 3 l -10 11 z"/></svg>');
}
<fieldset>
<legend>New Entry</a></legend>
<form method="post" action="./gridform" onsubmit="return validateForm()" class="new_entry">
<input type="checkbox" id="container_extra" class="hidden">
<input type="checkbox" id="item_extra" class="hidden">
<div tabindex="0" id="container">
<label for="container_select">Container</label>
<label class="icon icon_more" for="container_extra">[...]</label>
<label class="checkbox_del">
<input type="checkbox" id="del_C" name="icon_del" class="icon_del font_brighter" value="1">
</label>
<input type="text" name="container_input" id="container_input" />
<span class="dropdown"></span>
<select name="container" id="container_select">
<option disabled>select Container</option>
<option value="Home">Home</option>
<option value="Work">Work</option>
<option value="else">else...</option>
</select>
</div>
<div tabindex="4" id="submit">
<button>Send</button>
</div>
<div id="position">
<label for="position_select">Position</label>
<select name="position" id="position_select">
<option value="" selected="selected">choose</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div tabindex="1" id="color">
<label for="color_select">Color</label>
<select name="color" id="color_select">
<option value="a" selected="selected">choose</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
</select>
</div>
<div id="hr"></div>
<div id="name">
<label for="name_input">Name</label>
<label class="icon icon_more" for="item_extra">[...]</label>
<label class="checkbox_del">
<input type="checkbox" id="del_C" name="icon_del" class="icon_del font_brighter" value="1">
</label>
<input type="text" name="name" id="name_input" />
</div>
<div id="url">
<label for="url_input">Link</label>
<input type="text" name="url" id="url_input" />
</div>
<div id="user">
<label for="user_input">User</label>
<input type="text" name="user" id="user_input" />
</div>
<div id="password">
<label for="password_input">Password</label>
<input type="text" name="password" id="password_input" />
</div>
<div id="post_data">
<label for="post_data_text">POST Data</label>
<textarea name="post_data" id="post_data_text"></textarea>
</div>
<div id="notes">
<label for="notes_text">Notes</label>
<textarea name="notes" id="notes_text"></textarea>
</div>
</form>
</fieldset>
两个翻译的时长我都玩了很多,一直没找到合适的设置,尤其是关闭。
这可能吗?
如果是怎么办?
我自己得到的:
max-height: 1000px;
由此,浏览器计算展开1000px的时长,
但是菜单只有 100px 可以展开,而且速度越来越快:-)
我正在尝试创建一个网格形式,其中应该有两个区域可以通过单击“容器”和“名称”之后的 ([...]) 来显示。
为此,必须使用过渡更改高度和底部边距。
不幸的是,我无法创建平滑的运动。
但是自己找:
function validateForm() {
var url_input = document.getElementById("url_input");
var name_input = document.getElementById("name_input");
if (name_input.value == "" && url_input.value !== "") {
name_input.placeholder = "bitte eintragen";
return false;
} else {
return true;
}
}
document
.getElementById("container_select")
.addEventListener("change", fill_input);
function fill_input() {
// get selected value from pulldown
var select_value = document.getElementById("container_select").value;
// set input value with pulldown value
document.getElementById("container_input").value = select_value;
console.log("select_value " + select_value);
}
select {
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: "";
} /* HIDE ARROW FROM DOPDOWN */
select::-ms-expand {
display: none;
} /* HIDE ARROW FROM DOPDOWN */
.hidden {
display: none;
}
.font_brighter:hover {
filter: brightness(150%);
}
@media (prefers-color-scheme: dark) {
:root {
--darkest_grey: #1e1e1e;
--dark_grey: #333333;
--white: #e0e0e0;
--black: #000;
--red: rgb(114, 0, 0);
--lightred: #ff5458;
--grey: rgb(130, 130, 130);
}
}
* {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
*:focus {
outline: none;
}
body {
background: #1e1e1e;
padding: 30px;
}
fieldset {
width: 350px;
margin: 0;
padding: 15px 20px 10px 12px;
border-radius: 5px;
}
legend {
font-size: 1.4em;
color: var(--white);
}
.new_entry {
width: 350px;
display: grid;
grid-template-areas: "container submit " "position color" "hr hr" "name url" "user password" "post_data post_data" "notes notes";
grid-template-columns: 50% 50%;
grid-template-rows: auto auto auto auto;
grid-gap: 0em 0.5em;
background: var(--darkest_grey);
color: var(--white); /* padding: 1.2em; */
}
textarea:focus,
input[type="text"]:focus,
select:focus,
button:focus {
background: #444 !important;
}
.new_entry textarea {
height: calc(100% - 1.5em);
resize: none;
}
.new_entry button {
padding: 0.5em 0 0.5em 0;
}
.new_entry button:hover {
filter: brightness(120%);
}
.new_entry input:not([type="radio"]):not([type="checkbox"]),
.new_entry textarea,
.new_entry select,
.new_entry button {
width: 100%;
border: solid 1px var(--black);
background: var(--dark_grey);
border-radius: 3px;
color: lightslategray;
padding: 0.2em;
line-height: 1.5em;
}
.new_entry label {
display: inline;
padding-left: 0.5em;
font-family: serif;
}
/* DISPLAY NONE */
/*
.new_entry>div {margin-bottom: .8em;}
#container {grid-area: container;}
#delete {grid-area: delete;}
#delete>label {display: inline;}
#position {grid-area: position; display: none; }
#color {grid-area: color; display: none;}
#name {grid-area: name;}
#url {grid-area: url;}
#hr {grid-area: hr; height: 1px; background:var(--grey); display: none;}
#container_extra:checked~#color,#container_extra:checked~#position,#container_extra:checked~#hr, #item_extra:checked~#password, #item_extra:checked~#post_data, #item_extra:checked~#user, #item_extra:checked~#notes {display: inline;}
#container_extra:checked~ #container label.checkbox_del, #item_extra:checked~#name label.checkbox_del {display: inline;}
label.checkbox_del {display: none;}
#user {grid-area: user;display: none;}
#password {grid-area: password;display: none;}
#notes {grid-area: notes;display: none;}
#post_data {grid-area: post_data;display: none;}
#submit {grid-area: submit; }
*/
/* DISPLAY NONE */
/* TRANSITION */
.new_entry > div {
margin-bottom: 0.8em;
background: var(--darkest_grey);
}
#container {
grid-area: container;
}
#submit {
grid-area: submit;
}
#position {
grid-area: position;
}
#color {
grid-area: color;
}
#hr {
grid-area: hr;
height: 1px;
background: var(--grey);
}
#name {
grid-area: name;
}
#url {
grid-area: url;
}
#user {
grid-area: user;
}
#password {
grid-area: password;
}
#notes {
grid-area: notes;
}
#post_data {
grid-area: post_data;
}
#color,
#position,
#hr,
#password,
#post_data,
#user,
#notes {
margin-bottom: 0em;
overflow: hidden;
max-height: 0;
transition: max-height 0.6s linear, margin-bottom 0.4s linear;
/* transition: margin-bottom 2s;
transition: max-height 1s; */
/* transition:
max-height 0.8s linear,
margin-bottom 0.4s linear; */
}
#container_extra:checked ~ #color,
#container_extra:checked ~ #position,
#container_extra:checked ~ #hr,
#item_extra:checked ~ #password,
#item_extra:checked ~ #post_data,
#item_extra:checked ~ #user,
#item_extra:checked ~ #notes {
margin-bottom: 0.8em;
max-height: 1000px;
/* transition: max-height 0.3s ease-out 0.5s, margin-bottom 1.3s ease; */
transition: max-height 1s linear, margin-bottom 0.2s linear;
}
label.checkbox_del {
visibility: hidden;
transition: visible 1.5s;
}
#container_extra:checked ~ #container label.checkbox_del,
#item_extra:checked ~ #name label.checkbox_del {
visibility: visible;
transition: visible 1.5s;
}
/* TRANSITION */
#submit button {
width: 50%;
margin-top: 1.4em;
float: right;
color: var(--white);
}
.icon_more {
color: var(--grey);
font-size: 50%;
position: relative;
top: -1px;
left: 2px;
cursor: pointer;
}
.icon_del {
position: relative;
right: 0px;
top: 3px;
height: 12px;
width: 12px;
margin: 0;
}
.new_entry input::placeholder {
color: #ff2727;
}
.new_entry input[type="checkbox"] {
border: solid 1px var(--black);
background: var(--red);
border-radius: 3px;
cursor: pointer;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
transition-duration: 0.5s;
}
.new_entry input[type="checkbox"]:checked {
background-color: var(--lightred);
}
#container > input {
width: 82%;
}
#container > select {
width: 27.2px;
padding: 0.2em 0.2em 0.2em 0;
}
#container_select {
color: transparent;
}
#container_select option {
color: var(--white);
}
.dropdown {
display: inline;
background-repeat: no-repeat, repeat;
background-size: 20px 20px;
height: 20px;
width: 20px;
z-index: 55;
position: absolute;
cursor: pointer;
pointer-events: none;
margin: 6px 0 0 6px;
background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" fill="%23E0E0E0" viewBox="0 0 30 30"><path d="M 0 8 l 2 -3 l 9 9.33 l 8 -9.33 l 2 3 l -10 11 z"/></svg>');
}
<fieldset>
<legend>New Entry</a></legend>
<form method="post" action="./gridform" onsubmit="return validateForm()" class="new_entry">
<input type="checkbox" id="container_extra" class="hidden">
<input type="checkbox" id="item_extra" class="hidden">
<div tabindex="0" id="container">
<label for="container_select">Container</label>
<label class="icon icon_more" for="container_extra">[...]</label>
<label class="checkbox_del">
<input type="checkbox" id="del_C" name="icon_del" class="icon_del font_brighter" value="1">
</label>
<input type="text" name="container_input" id="container_input" />
<span class="dropdown"></span>
<select name="container" id="container_select">
<option disabled>select Container</option>
<option value="Home">Home</option>
<option value="Work">Work</option>
<option value="else">else...</option>
</select>
</div>
<div tabindex="4" id="submit">
<button>Send</button>
</div>
<div id="position">
<label for="position_select">Position</label>
<select name="position" id="position_select">
<option value="" selected="selected">choose</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div tabindex="1" id="color">
<label for="color_select">Color</label>
<select name="color" id="color_select">
<option value="a" selected="selected">choose</option>
<option value="red">red</option>
<option value="yellow">yellow</option>
<option value="green">green</option>
</select>
</div>
<div id="hr"></div>
<div id="name">
<label for="name_input">Name</label>
<label class="icon icon_more" for="item_extra">[...]</label>
<label class="checkbox_del">
<input type="checkbox" id="del_C" name="icon_del" class="icon_del font_brighter" value="1">
</label>
<input type="text" name="name" id="name_input" />
</div>
<div id="url">
<label for="url_input">Link</label>
<input type="text" name="url" id="url_input" />
</div>
<div id="user">
<label for="user_input">User</label>
<input type="text" name="user" id="user_input" />
</div>
<div id="password">
<label for="password_input">Password</label>
<input type="text" name="password" id="password_input" />
</div>
<div id="post_data">
<label for="post_data_text">POST Data</label>
<textarea name="post_data" id="post_data_text"></textarea>
</div>
<div id="notes">
<label for="notes_text">Notes</label>
<textarea name="notes" id="notes_text"></textarea>
</div>
</form>
</fieldset>
两个翻译的时长我都玩了很多,一直没找到合适的设置,尤其是关闭。
这可能吗?
如果是怎么办?
我自己得到的:
max-height: 1000px;
由此,浏览器计算展开1000px的时长,
但是菜单只有 100px 可以展开,而且速度越来越快:-)