[英]slideUp() and slideDown() don't work but slideToggle() does
In this JS Fiddle,在这个 JS 小提琴中,
http://jsfiddle.net/bGKLn/ http://jsfiddle.net/bGKLn/
I wanted to slide "content" up and down when "bottom" is hovered.当“底部”悬停时,我想上下滑动“内容”。 I can't get it to work, please help me out.
我无法让它工作,请帮助我。
I tried slideToggle() and it worked but..out of curiosity.. why doesn't this work?我尝试了 slideToggle() 并且它起作用了但是..出于好奇..为什么这不起作用?
HTML
<div id="content">Content</div>
<div id="bottom" onclick="togle()"></div>
CSS CSS
#content {
width: 400px;
border-left: 10px solid #FA802F;
border-right: 10px solid #FA802F;
text-align: center;
padding: 100px 0px 100px 0px;
display: none;
}
#bottom {
width: 420px;
height: 100px;
background-color: #FA602F;
border-bottom-left-radius: 100px;
border-bottom-right-radius: 100px;
}
Java script Java脚本
function togle() {
var x = document.getElementById("content");
if (x.style.display.value.match("none")) {
$("#content").slideDown("slow");
} else {
$("#content").slideUp("slow");
}
}
Replace代替
x.style.display.value.match("none")
with something like像
x.style.display != "block"
as x.style.display
returns a string, which has no value
property, and you'll get因为
x.style.display
返回一个没有value
属性的字符串,你会得到
function togle() {
var x = document.getElementById("content");
if (x.style.display != "block") {
$("#content").slideDown("slow");
} else {
$("#content").slideUp("slow");
}
}
or a little more jQuery'ish或多一点jQuery'ish
$('#content').is(':visible')
or a lot more jQuery'ish, just use slideToggle()
?或者更多的jQuery'ish,只需使用
slideToggle()
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.