简体   繁体   English

带有切换动画的按钮单击

[英]Button Click with Toggle Animate

I know this question has been asked before but I couldn't find the solution I needed.我知道以前有人问过这个问题,但我找不到我需要的解决方案。

I'm trying to make the ' product detail ' button on my website here a 'show more / show less' toggle button with a background linear fade.我正在尝试将我网站上产品详细信息”按钮设置为带有背景线性渐变的“显示更多/显示更少”切换按钮。 Currently, clicking the button animates to reveal the details as I want but the button disappears and you can't toggle back to close it again.目前,单击按钮动画以显示我想要的详细信息,但按钮消失,您无法切换回以再次关闭它。

This is my JQuery Code:这是我的 JQuery 代码:

jQuery(document).ready(function( $ ){
  $('#hiddenBlock').animate({height: '150px'});

  $('#showBlock').click(function(e) {
      e.preventDefault();
  $('#hiddenBlock').animate({height: '100%'}, "slow");
    });
    });

What am I missing??我错过了什么?? I've tried using.toggle() instead of animate - that didn't work.我尝试过 using.toggle() 而不是 animate - 那没有用。

I appreciate your question.我很欣赏你的问题。 You can do one things that firstly you change text of button你可以做一件事,首先你改变按钮的文本
onclick rather hiding it: onclick 而不是隐藏它:

$("button").on('click', function(){ 
  $(this).toggleClass("see-more"); 
});
$(".see-more").text("See Less");

Actually your button is hiding behind the "You might Also like" div if you see in inspect tools.实际上,如果您在检查工具中看到,您的按钮隐藏在“您可能还喜欢”div 后面。 you need make its position up through top: -100px or margin-top:-100px in #showBlock div您需要在 #showBlock div 中将其 position 设置为top: -100px 或 margin-top:-100px

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

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