简体   繁体   English

jQuery具有显示功能。 当我尝试在他们的代码中找到它时,我找不到。 关于javascript我不了解什么?

[英]jquery has a show function. When I try to find it in their code, I cannot. What don't I understand about javascript?

I'd like to know what the jquery show() function does, but cannot find it in their source. 我想知道jquery show()函数的作用,但无法在其源代码中找到它。 Can you please explain where it is, and what I need to understand better about javascript to be able to, or to have found it? 您能否解释一下它的位置,以及我需要什么才能更好地了解javascript或找到它?

I've looked in their source, which is here: 我查看了他们的来源,在这里:

https://code.jquery.com/jquery-3.4.1.js https://code.jquery.com/jquery-3.4.1.js

And searching "show(" doesn't find it. Neither does searching on "function show" 搜索“ show(”找不到它。搜索“ function show”都没有

I want to do the straight equivalent in direct javascript css, that's my goal. 我想在直接javascript CSS中做直接等效,这是我的目标。

As far as I can tell, I'm encountering the problem described with Chrome described in the the first answer here: 据我所知,我遇到的是第一个答案中所述的Chrome所描述的问题:

Proper way to reset a GIF animation with display:none on Chrome 重置带有显示的GIF动画的正确方法:Chrome上没有

I put in a bunch of css changes, and the css transitionrun and transitionstart events don't fire as expected, perhaps queued up as this answer says. 我进行了一系列CSS更改,并且CSS Transitionrun和transitionstart事件未按预期触发,也许像此答案所说的那样排队。 So, I'm trying to find out what show() does, so I can ideally just do it directly with javascript/css. 因此,我试图找出show()的作用,因此理想情况下,我可以直接使用javascript / css进行操作。 (and just to be clear, I'm not dealing with GIF. I'm applying a bunch of css changes, then setting style.transition, and am having plenty of timing problems, the events not firing as expected. So, what does jquery show do (ideally cause the Chrome queue to finish and fire the events right). (请注意,我没有处理GIF。我正在应用一堆CSS更改,然后设置style.transition,并且遇到了许多计时问题,这些事件未按预期触发。所以,该怎么办jQuery show do(最好使Chrome队列完成并正确触发事件)。

To your question where can I find this? 对您的问题where can I find this? , I found this: , 我找到了这个:

jQuery.fn.extend( {
    show: function() {
        return showHide( this, true );
    },

The showHide method will remove display styling from an element (and hide will set display: none showHide方法将删除元素的显示样式(并且hide将设置display: none

You cannot set a CSS transition for the display property. 您不能为display属性设置CSS过渡。 There are other options, like transitioning from opacity: 0 to opacity: 1 . 还有其他选项,例如从opacity: 0过渡到opacity: 1 You can add another class with JavaScript to the element. 您可以将另一个具有JavaScript的类添加到元素。

.element { opacity: 0; transition: opacity 0.4s; }
.element--show { opacity: 1; }

Since you're using jQuery, the easiest way is probably using jQuery's .fadeIn method for a fade animation. 由于您使用的是jQuery,最简单的方法可能是将jQuery的.fadeIn方法用于淡入淡出动画。 However, this is not the best solution when it comes to performance. 但是,这不是性能方面的最佳解决方案。

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

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