Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
42c25656
Commit
42c25656
authored
May 09, 2013
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13855: line-height animations. Close gh-1265.
(cherry picked from commit
3971c2eb
)
parent
e0f59600
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
62 deletions
+104
-62
css.js
src/css.js
+1
-1
effects.js
src/effects.js
+65
-61
effects.js
test/unit/effects.js
+38
-0
No files found.
src/css.js
View file @
42c25656
...
...
@@ -161,7 +161,7 @@ jQuery.extend({
}
},
//
Exclude the following css properties to add px
//
Don't automatically add "px" to these possibly-unitless properties
cssNumber
:
{
"columnCount"
:
true
,
"fillOpacity"
:
true
,
...
...
src/effects.js
View file @
42c25656
...
...
@@ -5,24 +5,26 @@ var fxNow, timerId,
animationPrefilters
=
[
defaultPrefilter
],
tweeners
=
{
"*"
:
[
function
(
prop
,
value
)
{
var
end
,
unit
,
tween
=
this
.
createTween
(
prop
,
value
),
parts
=
rfxnum
.
exec
(
value
),
var
tween
=
this
.
createTween
(
prop
,
value
),
target
=
tween
.
cur
(),
start
=
+
target
||
0
,
parts
=
rfxnum
.
exec
(
value
),
unit
=
parts
&&
parts
[
3
]
||
(
jQuery
.
cssNumber
[
prop
]
?
""
:
"px"
),
// Starting value computation is required for potential unit mismatches
start
=
(
jQuery
.
cssNumber
[
prop
]
||
unit
!==
"px"
&&
+
target
)
&&
rfxnum
.
exec
(
jQuery
.
css
(
tween
.
elem
,
prop
)
),
scale
=
1
,
maxIterations
=
20
;
if
(
parts
)
{
end
=
+
parts
[
2
];
unit
=
parts
[
3
]
||
(
jQuery
.
cssNumber
[
prop
]
?
""
:
"px"
);
if
(
start
&&
start
[
3
]
!==
unit
)
{
// Trust units reported by jQuery.css
unit
=
unit
||
start
[
3
];
// Make sure we update the tween properties later on
parts
=
parts
||
[];
// We need to compute starting value
if
(
unit
!==
"px"
&&
start
)
{
// Iteratively approximate from a nonzero starting point
// Prefer the current property, because this process will be trivial if it uses the same units
// Fallback to end or a simple constant
start
=
jQuery
.
css
(
tween
.
elem
,
prop
,
true
)
||
end
||
1
;
start
=
+
target
||
1
;
do
{
// If previous iteration zeroed out, double until we get *something*
...
...
@@ -38,11 +40,16 @@ var fxNow, timerId,
}
while
(
scale
!==
(
scale
=
tween
.
cur
()
/
target
)
&&
scale
!==
1
&&
--
maxIterations
);
}
// Update tween properties
if
(
parts
)
{
tween
.
unit
=
unit
;
tween
.
start
=
start
;
tween
.
start
=
+
start
||
+
target
||
0
;
// If a +=/-= token was provided, we're doing a relative animation
tween
.
end
=
parts
[
1
]
?
start
+
(
parts
[
1
]
+
1
)
*
end
:
end
;
tween
.
end
=
parts
[
1
]
?
start
+
(
parts
[
1
]
+
1
)
*
parts
[
2
]
:
+
parts
[
2
];
}
return
tween
;
}]
};
...
...
@@ -55,19 +62,18 @@ function createFxNow() {
return
(
fxNow
=
jQuery
.
now
()
);
}
function
createTween
s
(
animation
,
props
)
{
jQuery
.
each
(
props
,
function
(
prop
,
value
)
{
var
collection
=
(
tweeners
[
prop
]
||
[]
).
concat
(
tweeners
[
"*"
]
),
function
createTween
(
value
,
prop
,
animation
)
{
var
tween
,
collection
=
(
tweeners
[
prop
]
||
[]
).
concat
(
tweeners
[
"*"
]
),
index
=
0
,
length
=
collection
.
length
;
for
(
;
index
<
length
;
index
++
)
{
if
(
collection
[
index
].
call
(
animation
,
prop
,
value
)
)
{
if
(
(
tween
=
collection
[
index
].
call
(
animation
,
prop
,
value
)
)
)
{
// we're done with this property
retur
n
;
return
twee
n
;
}
}
});
}
function
Animation
(
elem
,
properties
,
options
)
{
...
...
@@ -153,7 +159,7 @@ function Animation( elem, properties, options ) {
}
}
createTweens
(
animation
,
props
);
jQuery
.
map
(
props
,
createTween
,
animation
);
if
(
jQuery
.
isFunction
(
animation
.
opts
.
start
)
)
{
animation
.
opts
.
start
.
call
(
elem
,
animation
);
...
...
@@ -243,14 +249,12 @@ jQuery.Animation = jQuery.extend( Animation, {
function
defaultPrefilter
(
elem
,
props
,
opts
)
{
/* jshint validthis: true */
var
prop
,
index
,
length
,
value
,
dataShow
,
toggle
,
tween
,
hooks
,
oldfire
,
var
prop
,
value
,
toggle
,
tween
,
hooks
,
oldfire
,
anim
=
this
,
style
=
elem
.
style
,
orig
=
{},
handled
=
[],
hidden
=
elem
.
nodeType
&&
isHidden
(
elem
);
style
=
elem
.
style
,
hidden
=
elem
.
nodeType
&&
isHidden
(
elem
),
dataShow
=
jQuery
.
_data
(
elem
,
"fxshow"
);
// handle queue: false promises
if
(
!
opts
.
queue
)
{
...
...
@@ -315,24 +319,26 @@ function defaultPrefilter( elem, props, opts ) {
// show/hide pass
for
(
index
in
props
)
{
value
=
props
[
index
];
for
(
prop
in
props
)
{
value
=
props
[
prop
];
if
(
rfxtypes
.
exec
(
value
)
)
{
delete
props
[
index
];
delete
props
[
prop
];
toggle
=
toggle
||
value
===
"toggle"
;
if
(
value
===
(
hidden
?
"hide"
:
"show"
)
)
{
continue
;
}
handled
.
push
(
index
);
orig
[
prop
]
=
dataShow
&&
dataShow
[
prop
]
||
jQuery
.
style
(
elem
,
prop
);
}
}
length
=
handled
.
length
;
if
(
length
)
{
dataShow
=
jQuery
.
_data
(
elem
,
"fxshow"
)
||
jQuery
.
_data
(
elem
,
"fxshow"
,
{}
);
if
(
!
jQuery
.
isEmptyObject
(
orig
)
)
{
if
(
dataShow
)
{
if
(
"hidden"
in
dataShow
)
{
hidden
=
dataShow
.
hidden
;
}
}
else
{
dataShow
=
jQuery
.
_data
(
elem
,
"fxshow"
,
{}
);
}
// store state if its toggle - enables .stop().toggle() to "reverse"
if
(
toggle
)
{
...
...
@@ -352,10 +358,8 @@ function defaultPrefilter( elem, props, opts ) {
jQuery
.
style
(
elem
,
prop
,
orig
[
prop
]
);
}
});
for
(
index
=
0
;
index
<
length
;
index
++
)
{
prop
=
handled
[
index
];
tween
=
anim
.
createTween
(
prop
,
hidden
?
dataShow
[
prop
]
:
0
);
orig
[
prop
]
=
dataShow
[
prop
]
||
jQuery
.
style
(
elem
,
prop
);
for
(
prop
in
orig
)
{
tween
=
createTween
(
hidden
?
dataShow
[
prop
]
:
0
,
prop
,
anim
);
if
(
!
(
prop
in
dataShow
)
)
{
dataShow
[
prop
]
=
tween
.
start
;
...
...
test/unit/effects.js
View file @
42c25656
...
...
@@ -1405,6 +1405,44 @@ test("Do not append px to 'fill-opacity' #9548", 1, function() {
});
});
test
(
"line-height animates correctly (#13855)"
,
function
()
{
expect
(
12
);
stop
();
var
animated
=
jQuery
(
"<p style='line-height: 4;'>unitless</p>"
+
"<p style='line-height: 50px;'>px</p>"
+
"<p style='line-height: 420%;'>percent</p>"
+
"<p style='line-height: 2.5em;'>em</p>"
).
appendTo
(
"#qunit-fixture"
),
initialHeight
=
jQuery
.
map
(
animated
,
function
(
el
)
{
return
jQuery
(
el
).
height
();
});
animated
.
animate
(
{
"line-height"
:
"hide"
},
1500
);
setTimeout
(
function
()
{
animated
.
each
(
function
(
i
)
{
var
label
=
jQuery
.
text
(
this
),
initial
=
initialHeight
[
i
],
height
=
jQuery
(
this
).
height
();
ok
(
height
<
initial
,
"hide "
+
label
+
": upper bound"
);
ok
(
height
>
initial
/
2
,
"hide "
+
label
+
": lower bound"
);
});
animated
.
stop
(
true
,
true
).
hide
().
animate
(
{
"line-height"
:
"show"
},
1500
);
setTimeout
(
function
()
{
animated
.
each
(
function
(
i
)
{
var
label
=
jQuery
.
text
(
this
),
initial
=
initialHeight
[
i
],
height
=
jQuery
(
this
).
height
();
ok
(
height
<
initial
/
2
,
"show "
+
label
+
": upper bound"
);
});
animated
.
stop
(
true
,
true
);
start
();
},
400
);
},
400
);
});
// Start 1.8 Animation tests
asyncTest
(
"jQuery.Animation( object, props, opts )"
,
4
,
function
()
{
var
animation
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment