[英]jquery switch action on a button after click
I'm trying to toggle between an two actions on a button. 我试图在一个按钮上的两个动作之间切换。
Currently clicking 'Top / Reveal' works when the yellow block scrolls up. 当黄色方块向上滚动时,当前单击“顶部/显示”即可。 Clicking the button again should then move the yellow block down to reveal the height of the green block.
再次单击该按钮,然后应将黄色块向下移动以显示绿色块的高度。
HTML 的HTML
<div class="block">
<h2>This is green block is fixed</h2>
</div>
<div class="content" id="here">
<div class="headerbar"> <a href="#here">Top / Reveal</a>
</div>
</div>
JS JS
$("a href='#here'").click(function () {
$("html, body").animate({
scrollTop: 0
}, "slow");
return false;
});
Just toggle your scrollTop
param like so: 只需像这样切换您的
scrollTop
参数:
scrollTop: $("body").scrollTop() == 0 ? 300 : 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.