简体   繁体   English

在点击事件期间如何淡入元素?

[英]How can I fadeIn elements during a click event?

More specifically, I want to fade one by one my a elements from my mobile-container when the transition of the mobile-container transitions stops when it's opened. 更具体地讲,我想通过我的一个褪色一个a从我的元素mobile-container时的过渡mobile-container它打开时转换停止。 This website has exactly what I'm trying to achieve. 这个网站正是我想要达到的目标。

Here is a link to my codepen. 是我的Codepen的链接。

Bellow is my code.. without the Sass and Jquery files because the indentation on stack overflow is killing me. 贝娄是我的代码..没有Sass和Jquery文件,因为堆栈溢出的缩进使我丧命。

Jade: 玉:

nav
 a(id='brand') ecostudent
 ul(class='main-navigation')
  li
   a lorem
  li
   a lorem
  li
   a lorem
  li
   a lorem 
 div(class='menu-wrapper')
  div(class='line-menu top')
  div(class='line-menu bottom')
 div(class='mobile-container')
  ul(class='mobile-navigation')
   li
    a lorem
   li
    a lorem
   li
    a lorem
   li
    a lorem
   div(class='menu-closing-wrapper')
    div(class='line-menu top')
    div(class='line-menu bottom')

You can use transition-delay combined with sass loops and completely avoid javascript: 您可以将transition-delay与sass循环结合使用,完全避免使用javascript:

@for $i from 0 through 3
  .mobile-container.active li:nth-child(#{$i})
    transition-delay: 330ms + (100ms * $i) !important

Check this fork of your codepen. 检查这个叉子的codepen的。

You can use jquery plugin https://github.com/morr/jquery.appear/ to track elements when they appear and provide data animations based on it. 您可以使用jquery插件https://github.com/morr/jquery.appear/跟踪元素出现的时间,并根据其提供数据动画。

Eg You can give your element and attribute data-animated="fadeIn" and the plugin will do the rest. 例如,您可以将元素和属性设置为data-animated =“ fadeIn”,然后插件将完成其余工作。

The fastest way is probably just to loop through each list item and create a setTimeout for a fade-in. 最快的方法可能只是遍历每个列表项并为淡入创建一个setTimeout。 My jquery is a little rusty but something like this: 我的jquery有点生锈,但是像这样:

$('.mobile-navigation li').each(function(index,item) {
    setTimeout( function(){$(item).fadeIn();}, index*100);
});

暂无
暂无

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

相关问题 如何仅针对某些元素覆盖 javascript 单击事件? - How can I override javascript click event for only certain elements? 对单击事件的fadeIn效果 - fadeIn effect for a click event 如果click事件冒泡到绑定到同一点击处理程序的元素,我如何隔离点击的初始目标? - How can I isolate the initial target of a click, if the click event bubbles up to elements bound to the same click handler? 我如何为由于附近其他元素调用$ .fadeIn()而移动的元素制作动画? - How can I animate elements that move due to other nearby elements having $.fadeIn() called on them? 我如何在jQuery click事件期间检索列表项的子位置? - How can I retrieve the child position of a list item during a jQuery click event? 如何让我的“点击”事件处理程序引用这些特定元素? - How can I get my 'click' event handler to reference these specific elements? 如何在React中将点击事件从父元素传递给子元素? [ C ] - How can I pass a click event from a parent to child elements in React? [ c ] 如何基于addEventListener上的点击事件通过父元素在shadow dom中select元素? - How can I select elements in shadow dom through the parent element based on the click event on addEventListener? 如何让Chrome在FadeIn()期间应用字体平滑? - How do I get Chrome to apply font smoothing during FadeIn()? 如何隐藏(和淡入)所选的选择? - How can I hide (and fadeIn) a chosen select?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM