Bug Tracker

Opened 8 years ago

Closed 7 years ago

#11585 closed bug (worksforme)

fadeTo sets css display

Reported by: Knotschi Owned by:
Priority: high Milestone: 1.8
Component: css Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

After switching from 1.7.1 to 1.7.2 I had some problems with the fadeTo function.
In older versions the fadeTo function only changed the opacity. But in the newest version it sometimes also changes the display style.
That caused some errors in my application and it took me some time to find these because i couldn't find any changes for the fadeTo function in your release notes.
You can see what I mean here: http://jsfiddle.net/MDVFq/1/
The last console output is "inline" with jquery 1.7.2 but "block" with 1.7.1

Change History (8)

comment:1 Changed 7 years ago by Rick Waldron

Component: unfiledcss
Priority: undecidedhigh
Status: newopen

Confirmed

comment:2 Changed 7 years ago by Rick Waldron

Milestone: None1.8

comment:3 Changed 7 years ago by markel

FadeTo and other animate aliases set display for hidden elements to be sure that element will be shown. Even through disconnected elements (like in your example) always considered to be hidden, but jQuery was failing to set display on them before 1.7.2, like it was described in 10006 ticket.

The thing is, jQuery cannot know beforehand what styles is applied to disconnected nodes and where element will end up with. So to be sure that element will eventually be shown, it sets display on the element.

Easy fix for you will be to use animate for opacity or set css style to:

.test a{display:block !important; text-align:center;}​}}}

comment:4 in reply to:  3 Changed 7 years ago by Knotschi

I know that behaviour and exactly that was why I used fadeTo instead of fadeIn. In the past I always used fadeTo when I didn't wanted the display to be set. In the documentation of fadeTo stands only: "The .fadeTo() method animates the opacity of the matched elements." Nothing with showing or hiding or setting the display.

If you want that new behaviour with also setting the display in fadeTo, you really should write it in the release notes of 1.7.2!! If I would have read it there, I wouldn't had to search for the error in my application so long by my own after changing the jquery version. I didn't thought about you could change the fadeTo behaviour(without writing it in the release notes).

And you also should write that behaviour in the documentation that it not only animates the opacity but also setting the display value / shows the element!

(I prefered the fadeTo behaviour of 1.7.1 with only changing opacity, but that is your decision)

Replying to markel:

FadeTo and other animate aliases set display for hidden elements to be sure that element will be shown. Even through disconnected elements (like in your example) always considered to be hidden, but jQuery was failing to set display on them before 1.7.2, like it was described in 10006 ticket.

The thing is, jQuery cannot know beforehand what styles is applied to disconnected nodes and where element will end up with. So to be sure that element will eventually be shown, it sets display on the element.

Easy fix for you will be to use animate for opacity or set css style to:

.test a{display:block !important; text-align:center;}​}}}

comment:5 Changed 7 years ago by markel

Difference between fadeIn and fadeTo methods is only that in fadeIn function you can't specify exact number for opacity, nothing more, all aliases for animate method Always set display for hidden elements, this action is implied for them – how you can see an animation if element is hidden? It doesn't make sense, fadeTo always used jQuery.fn.show for hidden elements, and changes for jQuery.fn.show is in release notes.

To clarify – i'm not a part of jQuery team, i can't write release notes or a documentation, however i'm responsable for this behavior change in newest jQuery. I'm sorry that you spend your time and nerves to find a bug, i know how frustrating it can be, but i really think newst change is the right one.

comment:6 Changed 7 years ago by Knotschi

Hmm okay, i just looked in the jquery code and see that also in older releases it should have set the display, this just doesn't worked. So it really was a Bug in older version. I always thought the wanted behaviour was without calling show. That explains why there was nothing in the release notes about the fadeTo fn. Nothing changed on fadeTo, only in the show function.

Imho it would be better if somebody writes it in the documentation that it also shows hidden elements. But you are right, I only didn't expected this behaviour because showing doesn't worked in older versions of fadeTo and I got used to it.

But than this here really isn't a Bug and can be closed I think.

comment:7 Changed 7 years ago by markel

Thank you for understanding, i also created related enchantment because of this ticket – http://bugs.jquery.com/ticket/11755, and associated PR - https://github.com/jquery/jquery/pull/774

If it will be accepted, it will revert previous behavior without breaking #10006 and will make animate set display only if it really need to

comment:8 Changed 7 years ago by dmethvin

Resolution: worksforme
Status: openclosed

This is working as intended.

Note: See TracTickets for help on using tickets.