我一直在努力制作不同方向和大小的全屏响应滑动div元素,我在这里找到了这种方法。
$(document).click(function () {
$(".page").toggleClass("in");
});
这就是我要做的事。
<span id="button">open slider 1</span>
<span id="button2">open slider 2</span>
<span id="button3">open slider 3</span>
<div id="slider">
<span id="button4">close</span>
</div>
<div id="slider2">
<span id="button5">close</span>
</div>
<div id="slider3">
<span id="button6">close</span>
</div>
此图片还显示我正在尝试做的事情。点击here
感谢您阅读此内容并希望有人可以帮我构建此内容。 感谢。
答案 0 :(得分:2)
<强> JS 强>
$('#button').click(function(){
$('#slider').addClass('in');
});
$('#button2').click(function(){
$('#slider2').addClass('in');
});
$('#button3').click(function(){
$('#slider3').addClass('in');
});
$('#button4').click(function(){
$('#slider').removeClass('in');
});
$('#button5').click(function(){
$('#slider2').removeClass('in');
});
$('#button6').click(function(){
$('#slider3').removeClass('in');
});
<强> HTML 强>
<div style="height:100%">
<span id="button">open slider 1</span>
<span id="button2">open slider 2</span>
<span id="button3">open slider 3</span>
<div id="slider"> <span id="button4">close</span>
</div>
<div id="slider2"> <span id="button5">close</span>
</div>
<div id="slider3"> <span id="button6">close</span>
</div>
</div>
<强> CSS 强>
html {
height: 100%;
}
body {
position: relative;
height: 100%;
width: 100%;
overflow: hidden;
margin:0;
}
.page.in {
left: 0;
z-index: 1;
}
#slider {
position: absolute;
width: 100%;
height: 50%;
bottom: 100%;
background: yellow;
transition: bottom 1s;
}
#slider.in {
bottom:50%;
}
#slider2 {
position: absolute;
width: 50%;
height: 100%;
left:100%;
top:0;
background: red;
transition: left 1s;
}
#slider2.in {
left:50%;
}
#slider3 {
position: absolute;
width: 100%;
height: 100%;
top:100%;
background: blue;
transition: top 1s;
}
#slider3.in {
top:0;
}
答案 1 :(得分:0)
您需要为每个滑块div建立2个css类,一个用于显示时间,另一个用于不显示时。然后你的代码就像单击按钮时更改元素的类一样简单。
一种可能性:
.slider {
position: absolute;
overflow: hidden;
}
.slider.top {
top: -50%;
left: 0px;
transition: top 1s;
height: 50%;
width: 100%;
background: red;
}
.slider.top.in {
top: 0%;
}
.slider.right {
left: 100%;
top: 0px;
transition: left 1s;
height: 100%;
width: 50%;
background: yellow;
}
.slider.right.in {
left: 50%;
}
.slider.bottom {
top: 100%;
left: 0px;
transition: top 1s;
height: 50%;
width: 100%;
background: blue;
color: cyan;
}
.slider.bottom.in {
top: 50%;
}
查询
$("#button").click(function(){$("#slider").addClass("in");});
$("#button2").click(function(){$("#slider2").toggleClass("in");});
$("#button3").click(function(){$("#slider3").toggleClass("in");});
$(".closebutton").click(function(){$(this).parent().removeClass("in");});
HTML
<p><span id="button">open slider 1</span></p>
<p><span id="button2">open slider 2</span></p>
<p><span id="button3">open slider 3</span></p>
<div id="slider" class="top slider">
<span id="button4" class="closebutton">close</span>
</div>
<div id="slider2" class="right slider">
<span id="button5" class="closebutton">close</span>
</div>
<div id="slider3" class="bottom slider">
<span id="button6" class="closebutton">close</span>
</div>