-
Notifications
You must be signed in to change notification settings - Fork 20.6k
.css(), the values like +=10% aren't ignored anymore (like .animate()) #2011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the followup! I think you will see some problems if you run the effects test suite against this code. Also, I think more thought needs to go into handling extreme values (zero, very small, very large)—which is the reason for do...while in effects.js. And finally, this new functionality should come with unit tests so we can ensure its correct behavior on all platforms into the future. |
Hi @gibson042 :) I forgot to check the division by zero, shame on me... I have update my commit. I didn't understand what you mean by very small value it's between 0 and 1 pixel? It make sens for me only if we could multiply a value like when we multiply a |
"Very small" in the sense of "risking problems from rounding errors". The easiest way to get them is mixing "%" and non-"%", e.g. between And again, all of this should have unit tests. |
Here I put several examples with the current jQuery And here it's the same but with my changes (without the loop). The width of the blue bars are hard-fixed with the correct value and never move. I wrote your example ( |
You're still dealing with smallish values, but dimensions can get arbitrarily large (remember, "%" is always relative)—the loop is a guarantee that we can establish an accurate scale even for extreme values. All of which, of course, is completely beside the point while this PR is not adding unit tests for new functionality and is failing existing effects tests. |
I saw these failing tests, I will extract the loop in the common function this evening. |
Best judgment, and trying to preserve the surrounding style. In this case, I'd like to see a new test immediately after the existing relative-value test in test/unit/css.js that looks something like: test( "css() non-px relative values (gh-1711)", <N>, function() {
…
}); and covers various non-px scenarios. |
I made a new commit (all tests are passing). And another thing: why not make an alias on: I think it can be a great save a code, no? |
@@ -285,7 +286,7 @@ jQuery.extend({ | |||
|
|||
// If a number was passed in, add 'px' (except for certain CSS properties) | |||
if ( type === "number" && !jQuery.cssNumber[ origName ] ) { | |||
value += "px"; | |||
value += ret && ret[3] ? ret[3] : "px"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick but you should have spaces inside the square brackets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks (it's done) :)
"../var/rfxnum" | ||
], function( jQuery, rfxnum ) { | ||
|
||
function cssCastUnit( elem, prop, parts, tween ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables here could have better names, especially now that this code is a fully-fledged function serving two purposes. I recommend something like:
- cssCastUnit → adjustCSS
- parts → value
- getCSS → currentValue
- target → initial
- start → recasted
- end → adjusted
👏 @mr21; this is looking great! |
All is done @gibson042 :) I found a probleme with Thanks for all these indications! |
Yep, that's exactly the kind of thing I was hoping to uncover.
Thank you; I will try to look it over again today. Also, squashing everything into a single commit makes it hard to see changes over the course of this pull request... in the future, please add new commits and fast-forward instead of force-pushing replacements. |
Understood 👍 |
], function( jQuery, pnum, access, rmargin, rnumnonpx, cssExpand, isHidden, | ||
getStyles, curCSS, defaultDisplay, addGetHookIf, support, dataPriv ) { | ||
], function( jQuery, pnum, rfxnum, access, rmargin, rnumnonpx, cssExpand, isHidden, | ||
getStyles, curCSS, adjustCSS, defaultDisplay, addGetHookIf, support, dataPriv ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep the "r" variables together (e.g., rfxnum
before or after rnumnonpx
).
unit = value && value[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), | ||
// Starting value computation is required for potential unit mismatches | ||
recasted = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) && | ||
rfxnum.exec( jQuery.css( elem, prop ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing it all together, maybe a couple more renames are in order:
value
→valueParts
recasted
→initialInUnit
Almost there! Thanks again, @mr21. |
All is done (in a new commit this time). |
Just one more thing before this lands (and sorry I didn't check earlier)... make sure to sign our CLA with the same email address you use for GitHub commits. |
Done :) |
Thanks @mr21! 👍 |
Great ^^ |
Nope; just leave this as-is and I expect to merge within the next seven days (and definitely before the 3.0 beta). Thanks again! |
Thanks again, @mr21! |
You're welcome 😄 |
Hi :)
Actually when we make:
$element.animate({width: "+=10%"}, 500);
it's work fine, the value is converted into percentage BUT if we write:
$element.css("width", "+=10%");
We don't have the same behavior...
The
.css()
function doesn't look the unity, it's"px"
every time.The deletion of my two old commit has closed my last pull request... and even when I make another new commit I can't reopen it, sorry for that doublon.
So, @gibson042 told me to see this part: https://github.com/jquery/jquery/blob/master/src/effects.js#L38-L60
Before, I didn't understand I could make a new CSS change on the element with
$.style
just for make the calcul conversion about the different CSS unities.When I understand this, I understand the code BUT I didn't understand (again) why it's necessary to make the
do{}while()
loop, because every time this loop is passed only one time for each call.