点击事件后,jQuery slideDown()函数对两个元素都不起作用

时间:2017-12-30 20:49:55

标签: javascript jquery html css

我想使用slideDown()函数制作动画,不管怎样,.quote-container都不包含在其中,即使slideDown()函数包含{{ 1}}和.quote-container元素。

为什么它们在第一个加载动画中工作?在第二个加载动画中(在点击事件之后),不要(仅#new-quote工作)? #new-quote仅在slideDown()动画结束后显示,即2秒。



.quote-container

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




1 个答案:

答案 0 :(得分:1)

问题已解决

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

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