[英]Show/Hide Div while using the same clickable link?
i recently came across this script: 我最近遇到过这个脚本:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("#showdiv").click(function(){
$(".dropdowndiv").slideDown(500);
});
$("#hide").click(function(){
$(".dropdowndiv").slideUp(500);
});
});
</script>
which i use to show and hide a div at the top of my page that bring down the entire page. 我用它来显示和隐藏页面顶部的一个div,它会打开整个页面。 The code works simply enough, you click on a link it slides the page down showing the div, you click on another link it hides the div, this all while doing a slid in and out motion.
代码工作得足够简单,你点击一个链接,它向下滑动页面显示div,你点击另一个链接它隐藏div,这一切都在滑动进出动作。 I was wondering if there was a way to instead of clicking on two different links i could use the fist link to slide open and slide the div closed?
我想知道是否有办法而不是点击两个不同的链接我可以使用第一个链接滑动打开并滑动div关闭?
You can see a live preview on my tumblr here: cielprince.tumblr.com 你可以在我的tumblr上看到一个实时预览:cielprince.tumblr.com
you mean, using slideToggle : 你的意思是,使用slideToggle :
$("#showdiv").click(function () {
$(".dropdowndiv").slideToggle("slow");
});
$("#showdiv").click(function () {
$(".dropdowndiv").stop().slideToggle();
});
.stop
is done to prevent queuing of animations on repeated clicks. .stop
用于防止重复点击时排队动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.