简体   繁体   English

jQuery使用按钮上下切换div

[英]jquery toggle div up and down using button

Hope your all well... Heres my jquery code at the moment- only moving the div up (not down): 希望您一切都好...目前这是我的jquery代码-仅将div向上移动(而不向下):

$("#thedacbutton").click(function(){ 
    $(".thedacALLCONTENT").animate({"top":"-=558px"}, 400, 'linear');
    });

I want "thedacALLCONTENT" to move up when "thedacbutton" is clicked and move back to its orginal place once clicked again (down). 我希望单击“ thedacbutton”时将“ thedacALLCONTENT”向上移动,并再次单击(向下),使其移回其原始位置。 Like a toggle... Any help greatly appreciated, thanks- Tom 像拨动开关一样。感谢您的任何帮助,汤姆

I am not 100% sure.. what you are upto with this very less details. 我不是100%确信..您对这个少得多的细节有什么看法。 but you can try something like 但您可以尝试类似

var flag = true;
$("#thedacbutton").click(function(){ 
    if(flag){
     $(".thedacALLCONTENT").animate({"top":"-=558px"}, 400, 'linear');
     flag = false;
    }else{
     $(".thedacALLCONTENT").animate({"top":"+=558px"}, 400, 'linear');
     flag = true;
    }
});

How about using slideToggle() ? 如何使用slideToggle()呢?

$("#thedacbutton").click(function(){ 
    $(".thedacALLCONTENT").slideToggle();
});

Quick jsFiddle example . 快速jsFiddle示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM