🌐 AI搜索 & 代理 主页
Skip to content

Commit e2ef39b

Browse files
author
lidongjie
committed
group clip support effects, fix #57
1 parent 6f0d5dd commit e2ef39b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

example/test-group-clip.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
image.onload = () => {
2222
const clipPath = 'M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z';
23+
const leamonPath = 'M235.946483,75.0041277 C229.109329,53.4046689 214.063766,34.845093 195.469876,22.3846101 C175.428247,8.9577702 151.414895,2 127.314132,2 C75.430432,2 31.6212932,32.8626807 18.323944,74.9130141 C8.97646468,77.1439182 2,85.5871171 2,95.7172992 C2,104.709941 7.49867791,112.371771 15.2700334,115.546944 C15.8218133,115.773348 16.6030463,122.336292 16.8270361,123.236385 C22.1235768,144.534892 35.4236577,163.530709 52.5998558,176.952027 C52.6299032,176.976876 52.6626822,177.001726 52.6954612,177.026575 C72.5513428,192.535224 98.5478246,202 127.043705,202 C152.034964,202 176.867791,194.597706 197.428422,180.146527 C215.659011,167.335395 230.201962,148.621202 236.52831,126.969284 C237.566312,123.421373 238.549682,119.685713 239.038636,116.019079 C239.044099,115.983185 239.074146,115.444787 239.082341,115.442025 C246.673412,112.184022 252,104.580173 252,95.7172992 C252,85.6892748 245.15192,77.3371896 235.946483,75.0041277';
2324
const group = new Group({
2425
pos: [300, 300],
2526
anchor: [0.5, 0.5],
@@ -58,10 +59,12 @@
5859
});
5960

6061
group.animate([
61-
{bgcolor: 'red'},
62-
{bgcolor: 'green'},
62+
{ clip: { d: clipPath, transform: { scale: 5 } } },
63+
{ clip: { d: leamonPath }, offset: 0.5 },
64+
{ clip: { d: clipPath, transform: { scale: 3 } } },
6365
], {
64-
duration: 2000,
66+
duration: 10000,
67+
iterations: Infinity
6568
});
6669

6770
sprite.on('click', (evt) => {

src/group.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {parseValue, attr, flow, relative} from './utils';
22
import BaseSprite from './basesprite';
33
import {registerNodeType} from './nodetype';
4-
import {createSvgPath} from './helpers/path';
4+
import {createSvgPath, pathEffect} from './helpers/path';
55

66
import BaseNode from './basenode';
77
import DataNode from './datanode';
@@ -354,4 +354,12 @@ export default class Group extends BaseSprite {
354354
Object.assign(Group.prototype, groupApi);
355355
Group.applyLayout('flex', layout.flexLayout);
356356

357+
Group.setAttributeEffects({
358+
clip(clip1, clip2, p, start, end) {
359+
clip1 = createSvgPath(clip1);
360+
clip2 = createSvgPath(clip2);
361+
return pathEffect(clip1.d, clip2.d, p, start, end);
362+
},
363+
});
364+
357365
registerNodeType('group', Group, true);

0 commit comments

Comments
 (0)