.fadeTo not able to delay to fade

自古美人都是妖i 提交于 2019-12-12 06:15:28

问题


Trying to delay fade 500 to 1000, but when i change .fadeTo('500', 1); to .fadeTo('1000', 1); it's not delay to fade. Same timing, no difference between 500 to 1000.

Jquery:

$(".more-post").one("click", function () {

  $('.bottom-post').addClass('show-more').fadeTo('500', 0);

  setTimeout(function(){

    $('.bottom-post').addClass('show-more').fadeTo('500', 1);

  },4000);
});

This Jquery fade very fast, So how to fade delay more .fadeTo('1000', 1);. Want to fade more slow. Thanks.


回答1:


When i removed the addClass() and changed $(".more-post").one to $(".more-post").on it started to work:

$(".more-post").on("click", function() {

  $('.bottom-post').fadeTo(5000, 0);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="more-post">Click me to see the fade<div>
    <div class="bottom-post">Fade me slow<div>

OR

You can use jqueryUI toggleClass here

$(".more-post").on("click", function() {
  $('.bottom-post').toggleClass('more-post', 3000).toggleClass("hide-post", 5000);
});
$(".hide-post").on("click", function() {
  $('.bottom-post').toggleClass("hide-post", 3000).toggleClass('more-post', 5000);
});
.more-post {
  opacity: 1;
}

.hide-post {
  opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="more-post">Click me to see slow fading<div>
  <p class="bottom-post hide-post">More stuff to be faded in</p>



回答2:


You should try to set fadeTo('3000', 1). Here 3000 means 3 seconds. You can increase it for more slow fading.



来源:https://stackoverflow.com/questions/32472983/fadeto-not-able-to-delay-to-fade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!