inn*_*ion 3 javascript css jquery css3
我有一个关于使用jquery hide函数进行CSS隐藏转换的问题.
我从codepen.io 创建了这个DEMO
在此演示中,您可以看到显示按钮.当你点击显示按钮然后.test和.user-imagediv打开与CSS过渡效果.
我想点击隐藏按钮然后.testdiv隐藏CSS过渡效果.
任何人都可以告诉我一个小例子我该怎么做?
CSS
<div class="container">
<div class="usr">Show</div>
<div class="test">
<div class="hide">Hide</div>
<div class="user-image" style="background-image:url(...);"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
$(document).ready(function() {
$('.usr').click(function() {
$(".test").show();
});
$(".hide").click(function() {
$(".test").hide();
});
});
Run Code Online (Sandbox Code Playgroud)
你根本不需要jQuery.检查此示例:
http://codepen.io/anon/pen/JdKWWW
.hide-show-element {
background-color: #eee;
height: 400px;
position: relative;
text-align: center;
width: 400px;
}
.hide-show-element input[type='checkbox'] {
display: none;
}
.hide-show-element label {
background-color: #a00;
border: 1px solid #111;
color: #fff;
display: block;
text-align: center;
transition-duration: 0.4s;
}
.hide-show-element label:after {
display: block;
content: "Show";
}
.hide-show-element input:checked + label {
background-color: #fff;
border: 1px solid #a00;
color: #a00;
}
.hide-show-element input:checked + label:after {
content: "Hide";
}
.test1 {
opacity: 0;
position: relative;
height: 0;
top: 20%;
transition-duration: 0.4s;
width: 0;
}
.hide-show-element input:checked ~ .test1 {
opacity: 1;
height: 200px;
width: 200px;
}Run Code Online (Sandbox Code Playgroud)
<div class="hide-show-element">
<input type="checkbox" id="toggle" />
<label for="toggle"></label>
<img class="test1" src="http://lorempixel.com/200/200" />
</div>Run Code Online (Sandbox Code Playgroud)