Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-core
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
劳工
scilla-core
Commits
20964f34
Commit
20964f34
authored
May 21, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加getPromise返回一个Promise实例,此方法会中断链式编码
增加linear缓动
parent
ae072eba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
25 deletions
+50
-25
Tween.ts
src/support/Tween.ts
+45
-25
ease.ts
src/tools/ease.ts
+5
-0
No files found.
src/support/Tween.ts
View file @
20964f34
...
...
@@ -31,10 +31,10 @@ export interface ITweenPlugin {
resolveLerp
(
fromValue
,
toValue
,
ratio
,
allowOutOfBounds
):
any
;
}
function
injectChildProps
(
target
,
key
,
value
){
if
(
typeof
value
===
'object'
)
{
function
injectChildProps
(
target
,
key
,
value
)
{
if
(
typeof
value
===
'object'
)
{
injectProp
(
target
[
key
],
value
)
}
else
{
}
else
{
target
[
key
]
=
value
;
}
}
...
...
@@ -140,6 +140,7 @@ export class Tween extends HashObject {
protected
duration
:
number
;
protected
onLoopComplete
:
Function
;
protected
onComplete
:
Function
;
protected
promise
:
any
;
constructor
(
host
:
any
,
target
:
any
,
options
?:
TweenOptions
,
plugins
=
[])
{
super
();
...
...
@@ -162,7 +163,7 @@ export class Tween extends HashObject {
/**
* 获取动画链(高级功能)
*/
get
queue
(){
get
queue
()
{
return
this
.
_queue
;
}
...
...
@@ -208,9 +209,9 @@ export class Tween extends HashObject {
currentValue
=
toValue
;
}
if
(
typeof
currentValue
===
'object'
)
{
if
(
typeof
currentValue
===
'object'
)
{
injectProp
(
target
[
key
],
currentValue
);
}
else
{
}
else
{
target
[
key
]
=
currentValue
;
}
}
...
...
@@ -229,15 +230,15 @@ export class Tween extends HashObject {
}
};
protected
getInitProps
(
fields
)
{
protected
getInitProps
(
fields
)
{
const
props
=
{};
for
(
let
field
of
fields
)
{
if
(
field
in
this
.
target
)
{
let
value
=
this
.
target
[
field
];
if
(
typeof
value
===
'object'
)
{
if
(
value
.
clone
)
{
if
(
typeof
value
===
'object'
)
{
if
(
value
.
clone
)
{
value
=
value
.
clone
();
}
else
{
}
else
{
injectProp
(
props
[
field
]
=
{},
this
.
target
[
field
]);
}
}
...
...
@@ -251,13 +252,18 @@ export class Tween extends HashObject {
/**
* 设置目标的属性
* @param props 属性对象
* @param immediately 是否立刻执行,而不是在下一帧
*/
set
(
props
)
{
set
(
props
,
immediately
=
false
)
{
this
.
_queue
.
push
({
action
:
'set'
,
props
});
if
(
this
.
autoPlay
)
{
this
.
_start
();
}
if
(
immediately
)
{
this
.
_set
(
props
,
immediately
);
}
return
this
;
}
...
...
@@ -267,7 +273,7 @@ export class Tween extends HashObject {
* @param duration 耗时(ms)
* @param ease 缓动方法
*/
to
(
props
,
duration
?:
number
,
ease
?:
Function
)
{
to
(
props
,
duration
?:
number
,
ease
?:
Function
)
{
this
.
_queue
.
push
({
action
:
'to'
,
props
,
duration
,
ease
});
if
(
this
.
autoPlay
)
{
this
.
_start
();
...
...
@@ -322,11 +328,6 @@ export class Tween extends HashObject {
}
}
private
_doPlay
=
(
resetLoopCounting
)
=>
{
addTween
(
this
.
target
,
this
);
this
.
_start
(
resetLoopCounting
);
};
/**
* 终止补间动画
*/
...
...
@@ -336,10 +337,26 @@ export class Tween extends HashObject {
this
.
host
.
cancelOnNextTick
(
this
.
onUpdate
);
}
protected
_set
(
props
)
{
this
.
status
=
STATUS
.
DO_SET
;
/**
* 返回一个Promise
*/
getPromise
()
{
return
new
Promise
(
resolve
=>
{
this
.
promise
=
{
resolve
};
})
}
private
_doPlay
=
(
resetLoopCounting
)
=>
{
addTween
(
this
.
target
,
this
);
this
.
_start
(
resetLoopCounting
);
};
protected
_set
(
props
,
immediately
=
false
)
{
injectProp
(
this
.
target
,
props
,
injectChildProps
);
this
.
_doNextAction
();
if
(
!
immediately
)
{
this
.
status
=
STATUS
.
DO_SET
;
this
.
_doNextAction
();
}
}
protected
_to
(
props
,
duration
,
ease
)
{
...
...
@@ -349,10 +366,10 @@ export class Tween extends HashObject {
this
.
fromProps
=
{};
for
(
let
key
in
props
)
{
let
value
=
this
.
target
[
key
];
if
(
typeof
value
===
'object'
)
{
if
(
value
.
clone
)
{
if
(
typeof
value
===
'object'
)
{
if
(
value
.
clone
)
{
value
=
value
.
clone
();
}
else
{
}
else
{
injectProp
(
props
[
key
]
=
{},
this
.
target
[
key
]);
}
}
...
...
@@ -377,7 +394,7 @@ export class Tween extends HashObject {
protected
_call
(
func
,
thisObj
,
params
)
{
this
.
status
=
STATUS
.
DO_CALL
;
func
.
apply
(
thisObj
,
params
);
func
.
apply
(
thisObj
||
this
.
host
,
params
);
this
.
_doNextAction
();
}
...
...
@@ -435,7 +452,7 @@ export class Tween extends HashObject {
}
};
protected
_onEnd
(){
protected
_onEnd
()
{
this
.
onLoopComplete
&&
this
.
onLoopComplete
();
if
(
this
.
loop
<
0
)
{
this
.
_doStart
();
...
...
@@ -444,6 +461,9 @@ export class Tween extends HashObject {
}
else
{
this
.
status
=
STATUS
.
IDLE
;
this
.
onComplete
&&
this
.
onComplete
();
this
.
promise
&&
this
.
promise
.
resolve
();
this
.
promise
=
null
;
}
}
}
\ No newline at end of file
src/tools/ease.ts
View file @
20964f34
...
...
@@ -5,6 +5,7 @@
*/
export
enum
Ease
{
linear
=
'linear'
,
quadIn
=
'quadIn'
,
quadOut
=
'quadOut'
,
quadInOut
=
'quadInOut'
,
...
...
@@ -34,6 +35,10 @@ export enum Ease {
elasticInOut
=
'elasticInOut'
,
}
export
function
linear
(
t
){
return
t
;
}
export
function
get
(
amount
)
{
if
(
amount
<
-
1
)
{
amount
=
-
1
;
...
...
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