我在解决一个问题上有困难。我有两个按钮,一个是slideUp的,另一个是slideDown的。我想要做的是有一个按钮来切换,而不是有两个。
谢谢。
我有一个html格式的代码:
<div id = "box">Show / Hide</div>
<button onclick="slideUp('box');">Slide Up</button>
<button onclick="slideDown('box');">Slide Down</button>
我用css编写了这段代码:
body{
background:grey;
}
#box{
width:400px;
height:400px;
background:orange;
margin:0 auto;
margin-top:3%;
overflow:hidden;
}
我的javascript代码是:
function slideUp(el) {
var elem = document.getElementById(el);
elem.style.transition = "all 2s ease-in-out";
elem.style.height = "0px";
}
function slideDown(el) {
var elem = document.getElementById(el);
elem.style.transition = "all 2s ease-in-out";
elem.style.height = "400px";
}
https://stackoverflow.com/questions/35672718
复制相似问题