繁体   English   中英

jQuery使用按钮上下切换div

[英]jquery toggle div up and down using button

希望您一切都好...目前这是我的jquery代码-仅将div向上移动(而不向下):

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

我希望单击“ thedacbutton”时将“ thedacALLCONTENT”向上移动,并再次单击(向下),使其移回其原始位置。 像拨动开关一样。感谢您的任何帮助,汤姆

我不是100%确信..您对这个少得多的细节有什么看法。 但您可以尝试类似

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;
    }
});

如何使用slideToggle()呢?

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

快速jsFiddle示例

暂无
暂无

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

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