【问题标题】:Fade-In with transition via CSS/jQuery通过 CSS/jQuery 淡入淡入
【发布时间】:2020-01-15 19:12:38
【问题描述】:

我在尝试向以下代码添加淡入过渡时跌跌撞撞。代码来自blog,正如您所见,它创建了一个可点击的菜单项,点击时会展开。我没有问题让代码按作者的意图工作。但是,我想使用自定义图形作为我的基本图像和子菜单,但这样做我无法将子菜单隐藏在基本菜单后面。我认为向他现有的代码引入淡入(或/或 CSS 和 jquery)转换会相当简单,这样一开始子菜单是不可见的(不透明度:0),然后在点击时淡入。你可以猜到,我的尝试失败了。

如何编写这些 sn-ps 以使 .et-pb-icon 类最初被隐藏并在过渡完成时实现 100% 的不透明度?

谢谢。

       <style>
          .has-transform, .transform_target .et-pb-icon {
            transition: all 400ms ease-in-out;
          } 
          .toggle-transform-animation {
            transform: none !important;
          }
          .transform_target {
            cursor: pointer;
          }
          .toggle-active-target.et_pb_blurb .et-pb-icon {
          background-color: transparent;
          }
       </style>

       <script>
          (function($) {
            $(document).ready(function(){
              $('.transform_target').click(function(){
                $(this).toggleClass('toggle-active-target');
                $('.has-transform').toggleClass('toggle-transform-animation');   
              });    
            });
          })( jQuery );   
          </script>

【问题讨论】:

    标签: jquery css fadein


    【解决方案1】:

    回答:

    终于找到了正确的代码。 (我使用 .et_pb_module_header 代替 .et_pb_module_icon 次要的仅使用文本作为关键字)。

    <style>
      .has-transform, .transform_target .et_pb_module_header {
        transition: all 400ms ease-in-out;
        opacity: 1;
      } 
      .toggle-transform-animation {
        transform: none !important;
        opacity: 0;
      }
      .transform_target {
        cursor: pointer;
      }
      .toggle-active-target.et_pb_blurb .et_pb_module_header {
        background-color: transparent;
      }
    </style>
    

    【讨论】:

      【解决方案2】:

      没有 HTML 部分不是 100%,但你不能做类似的事情

      .et-pb-icon {
          opacity: 0;
          transition: all 400ms ease-in-out;
      } 
      
      .has-transform, .transform_target .et-pb-icon {
          opacity: 1;
          transition: all 400ms ease-in-out;
      } 
      

      【讨论】:

      • 感谢您的回复。不幸的是,我无法让代码工作。这就是让我困惑的地方。我在该 sn-p 中的任何位置添加 opacity: 1; 的那一刻,它们的目标始终可见。我想我可以将目标隐藏在页面外,但这种方法对我来说似乎不优雅。
      • 试试这个,这样您就不会向父元素添加不透明度,而是将其添加到您尝试定位的子元素.et-pb-icon { opacity: 0; transition: all 400ms ease-in-out; } .has-transform .transform_target .et-pb-icon { opacity: 1; transition: all 400ms ease-in-out; } .has-transform{ transition: all 400ms ease-in-out; }
      • --再次感谢您的回复,丹。抱歉回复这么慢。我终于能够构建正确的 sn-p。我让它变得更加困难。见上文。
      猜你喜欢
      • 2020-03-29
      • 2011-10-01
      • 2015-05-27
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      • 2012-12-22
      • 2023-03-27
      相关资源
      最近更新 更多