jQuery Animate队列错误不起作用

时间:2016-09-08 14:41:53

标签: javascript jquery

我尝试过使用StackOverflow浏览多个解决方案,而主流解决方案似乎是queue: false但是这对我不起作用。

我只是想让.cover.controls同时动画,而开始和结束的结果是正确的,动画不是。

$(".cover .controls .scale").click(function() {
  $(".currently_playing .cover").animate({
    height: "50px",
    width: "50px",
    margin: "20px 80px 0 80px"
  }, {
    queue: false
  });
  $(".currently_playing .cover .controls").animate({
    height: "50px",
    width: "50px"
  }, {
    queue: false,
  });
});
.currently_playing .cover {
  float: left;
  margin: 20px 20px 5px 20px;
  height: 210px;
  width: 210px;
}
.currently_playing .cover img {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}
.currently_playing .cover .controls {
  position: absolute;
  height: 210px;
  width: 210px;
  z-index: 9999;
}
.currently_playing .cover .controls:hover {
  background: rgba(0, 0, 0, 0.75);
  -webkit-transition: all 0.3s ease;
  transition: all 0.3s ease;
}
.currently_playing .cover .controls .scale {
  position: absolute;
  bottom: 0;
  right: 0;
  height: 30px;
  width: 30px;
  background: url(http://i743.photobucket.com/albums/xx78/MrTIMarshall2512/artwork_scale_zps1ztoz3qv.png) no-repeat;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="currently_playing">
  <div class="cover">
    <div class="controls">
      <div class="scale"></div>
    </div>
    <img src="http://www.at40.com/cimages/var/plain_site/storage/images/repository/news/music-news/new-album-art-released-for-bruno-mars-unorthodox-jukebox/224005-1-eng-US/New-Album-Art-Released-For-Bruno-Mars-Unorthodox-Jukebox.jpg" alt="Bruno Mars, Unorthodox Jukebox album artwork">
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

您的问题可以通过对CSS进行一些更改来解决,不要仅对父cover的两个元素进行动画处理:

$(".cover .controls .scale").click(function() {
  $(".currently_playing .cover").animate({
    height: "50px",
    width: "50px",
    margin: "20px 80px 0 80px"
  });
});
.currently_playing .cover {
  float: left;
  margin: 20px 20px 5px 20px;
  height: 210px;
  width: 210px;
  position: relative;
}
.currently_playing .cover img {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}
.currently_playing .cover .controls {
  position: absolute;
  height: 100%;
  width: 100%;
  z-index: 9999;
  -webkit-transition: all 0.3s ease;
  transition: all 0.3s ease;
}
.currently_playing .cover .controls:hover {
  background: rgba(0, 0, 0, 0.75);
}
.currently_playing .cover .controls .scale {
  position: absolute;
  bottom: 0;
  right: 0;
  height: 30px;
  width: 30px;
  background:url(images/temp/artwork_scale.png) no-repeat;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="currently_playing">
  <div class="cover">
    <div class="controls">
      <div class="scale"></div>
    </div>
    <img src="http://www.at40.com/cimages/var/plain_site/storage/images/repository/news/music-news/new-album-art-released-for-bruno-mars-unorthodox-jukebox/224005-1-eng-US/New-Album-Art-Released-For-Bruno-Mars-Unorthodox-Jukebox.jpg" alt="Bruno Mars, Unorthodox Jukebox album artwork">
  </div>
</div>