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. 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. 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,它会打开整个页面。代码工作得足够简单,你单击一个链接它向下滑动页面显示div,你点击另一个链接它隐藏div,这一切都在滑动进出动作。我想知道是否有办法而不是点击两个不同的链接我可以使用第一个链接滑动打开并滑动div关闭?
You can see a live preview on my tumblr here: cielprince.tumblr.com
你可以在我的tumblr上看到现场预览:cielprince.tumblr.com
2 个解决方案
#1
2
you mean, using slideToggle:
你的意思是,使用slideToggle:
$("#showdiv").click(function () {
$(".dropdowndiv").slideToggle("slow");
});
#2
1
$("#showdiv").click(function () {
$(".dropdowndiv").stop().slideToggle();
});
.stop
is done to prevent queuing of animations on repeated clicks.
完成.stop是为了防止在重复点击时排队动画。
#1
2
you mean, using slideToggle:
你的意思是,使用slideToggle:
$("#showdiv").click(function () {
$(".dropdowndiv").slideToggle("slow");
});
#2
1
$("#showdiv").click(function () {
$(".dropdowndiv").stop().slideToggle();
});
.stop
is done to prevent queuing of animations on repeated clicks.
完成.stop是为了防止在重复点击时排队动画。