簡體   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