简体   繁体   English

slideUp/slideDown 动画仅在一个部分

[英]slideUp/slideDown animation only in one section

I have simple problem with my jQuery code.我的 jQuery 代码有一个简单的问题。 I created row of jumbotrons and a few of this jumbotrons are hidden with CSS and on button click I display them.我创建了一排超大屏幕,其中一些超大屏幕用 CSS 隐藏,单击按钮时我会显示它们。 This work for me but I have a problem with the animation on event slideUp.这对我有用,但我在事件 slideUp 上的动画有问题。 I want to see how my jumbotrons are slowly and animated hidden but when I click on my button Show less animation goes to bottom of page - not back to heading Example as I want.我想看看我的超大屏幕是如何缓慢并隐藏动画的,但是当我单击按钮时,显示较少的动画会转到页面底部 - 而不是我想要的标题示例。

here is my code on codepen.io这是我在codepen.io 上的代码

$("#pr").click(function() {
  if ($(this).text() == "Show more") {
    $(this).html("<button class=\"btn custom-btn1 \" type=\"submit\">Show less</button></a>");
    $(".hide-me").slideDown(1000);
  } else {
    $(this).html("<button class=\"btn custom-btn1 \" type=\"submit\">Show more</button></a>");
    $(".hide-me").slideUp("slow");
  }
  return false;
});

You could add an animation (that doesn't get queued) to scroll up straight after slideUp is called.您可以添加一个动画(不会排队)在调用 slideUp 后直接向上滚动。

$("#pr").click(function() {
  if ($(this).text() == "Show more") {
    $(this).html("<button class=\"btn custom-btn1 \" type=\"submit\">Show less</button></a>");
    $(".hide-me").slideDown(1000);
  } else {
    $(this).html("<button class=\"btn custom-btn1 \" type=\"submit\">Show more</button></a>");
    $(".hide-me").slideUp("slow");
    const body = $("html, body");
    body.animate({scrollTop: $(".portfolio").offset().top}, {queue: false});
  }
  return false;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM