簡體   English   中英

單擊事件后,jQuery slideDown()函數對兩個元素均不起作用

[英]jQuery slideDown() function doesn't work for both elements after click event

我想提出使用動畫slideDown()函數,不管怎樣, .quote-container不包含在里面,就算slideDown()函數包含.quote-container#new-quote的元素。

為什么它們在第一個加載動畫中起作用,而在第二個加載動畫中(在click事件之后)卻不起作用(僅#new-quote起作用)? .quote-container僅在slideDown()動畫結束后(即2秒)顯示。

 // slideDown() works only for #new-quote $("#new-quote").on("click", function() { $(".quote-container, #new-quote").slideUp(2000, function() { $(".quote-container, #new-quote") .css("display", "inline-block") .hide(); $(".quote-container, #new-quote").slideDown(2000); }); }); // slideDown() for both elements works var height = $(".quote-container").outerHeight(); $(".quote-container, #new-quote") .css("display", "inline-block") .hide(); $("#new-quote").css("height", height + 80); $(".quote-container").css("padding", "2.5rem"); $(".quote-container, #new-quote").slideDown(2000); 
 html, body { height: 100%; width: 100%; } body { margin: 0; padding: 0; background: #333; color: #333; font-family: sans-serif; } .v-wrap { height: 100%; text-align: center; } .v-wrap:before { content: ""; display: inline-block; vertical-align: middle; width: 0; height: 100%; } .quote-container { width: 31.25rem; background: #fff; margin: auto; vertical-align: middle; border-radius: 0.1875rem; padding: 0 2.5rem; border-top-right-radius: 0; border-bottom-right-radius: 0; display: none; } .quote-text { font-size: 1.625rem; } .quote-text i { margin-right: 0.6rem; } .quote-text p { display: inline; } .quote-author { font-size: 1rem; margin: 0 0.4rem 2rem 0; text-align: right; } .button { padding: 0.75rem; text-align: center; font-size: 1em; color: #fff; border-radius: 3px; display: inline-block; cursor: pointer; -webkit-user-select: none; user-select: none; } .button:not(#new-quote) { min-width: 1rem; min-height: 1rem; } .button:hover:not(#new-quote) { opacity: 0.8; } .button i { vertical-align: middle; } #new-quote { white-space: nowrap; writing-mode: vertical-lr; height: 100%; border-top-left-radius: 0; border-bottom-left-radius: 0; vertical-align: middle; background: #fff !important; position: relative; right: 0.25625rem; color: #333; padding: 0 .75rem; display: none; } #new-quote:before { content: ""; position: absolute; height: 100%; width: 0.0625rem; bottom: 0; left: 0; visibility: hidden; -webkit-transform: scaleY(0); transform: scaleY(0); -webkit-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out; } #new-quote:hover:before { visibility: visible; -webkit-transform: scaleY(1); transform: scaleY(1); } footer { font-size: 0.85rem; } footer a { position: relative; text-decoration: none; color: #fff; } footer a:before { content: ""; position: absolute; width: 100%; height: 1px; bottom: 0; left: 0; background: #fff; visibility: hidden; -webkit-transform: scaleX(0); transform: scaleX(0); -webkit-transition: all 0.3s ease-in-out 0s; transition: all 0.3s ease-in-out 0s; } footer a:hover:before { visibility: visible; -webkit-transform: scaleX(1); transform: scaleX(1); } 
 <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="v-wrap"> <div class="quote-container"> <div class="quote-text"> </div> <div class="quote-author"></div> <a id="tweet-quote" class="button"><i class="fa fa-twitter"></i></a> <a id="tumblr-quote" class="button"><i class="fa fa-tumblr"></i></a> </div> <div id="new-quote" class="button">New quote</div> <footer><a href="https://codepen.io/Kestis500">Created by LukasLSC</a></footer> </div> 

解決的問題

我需要刪除$(".quote-container, #new-quote").css("display", "inline-block").hide(); 從onclick事件行:

$("#new-quote").on("click", function() {
  $(".quote-container, #new-quote").slideUp(2000, function() {
    $(".quote-container, #new-quote").slideDown(2000);
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM