简体   繁体   中英

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):

$("#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). Like a toggle... Any help greatly appreciated, thanks- Tom

I am not 100% sure.. what you are upto with this very less details. 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() ?

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

Quick jsFiddle example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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