Skip to content

Commit f0abd9f

Browse files
committed
strokeDash is back!
1 parent 38e8f94 commit f0abd9f

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

README.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A jQuery plugin for path animation using CSS.
1212

1313
## Getting started
1414
Implementing this plugin is broken into two parts.
15-
Preparing your web-friendly data & Configuring lazy-line-painter.js
15+
Preparing your svg data & Configuring lazy-line-painter.js
1616

1717

1818
**Preparing your SVG data** <br>
@@ -26,19 +26,22 @@ Copy lazy line code and paste into your DOM ready function.
2626

2727

2828
**Configuring lazy-line-painter options** <br>
29-
A number of attributes can be setup before the line art is Painted,
29+
Style attributes, callbacks and other options can be setup before the line art is Painted,
3030
these include;
3131
```js
3232
'strokeWidth' // Adjust width of stroke
3333
'strokeColor' // Adjust stroke color
3434
'strokeCap' // Adjust stroke cap - butt | round | square
3535
'strokeJoin' // Adjust stroke join - miter | round | bevel
3636
'strokeOpacity' // Adjust stroke opacity 0 - 1
37+
'strokeDash' // Adjust stroke dash - '5, 5'
38+
3739
'onComplete' // Callback fired after animation finishes
3840
'onUpdate' // Callback fired on animation update
3941
'onStart' // Callback fired before animation starts
4042
'onStrokeStart' // Callback fires after each stroke animation starts
4143
'onStrokeComplete' // Callback fires after each stroke animation completes
44+
4245
'delay' // Delay before animation starts
4346
'overrideKey' // Set this property if you selector id doesn't match the key referencing your path data value within svgData.
4447
'speedMultiplier' // slow down or speed up the animation
@@ -68,22 +71,21 @@ var svgData = {
6871
'paths' : // this contains all your SVG path info
6972
[
7073
{
71-
'path': "M144.869,199c0....", // path string ,
72-
'duration':300, // time taken to animate that path
73-
'strokeColor':'#000000', // stroke color can be set individually
74-
'strokeWidth':3 // stroke width can be set individually
74+
'path': "M144.869,199c0....", // path string
75+
'duration':300, // path duration
76+
'strokeWidth': 3, // all style attr can be set individually
7577
'reverse': true // reverse stroke individually
76-
'ease': '' // ease stroke individually - i.e 'easeInOutExpo', 'easeOutBounce'
77-
'onStrokeStart': function(){console.log("Stroke started")} // Callback fires after the stroke animation starts
78-
'onStrokeComplete': function(){console.log("Stroke completed")} // Callback fires after the stroke
79-
'onStrokeUpdate': function(){console.log("Stroke update")} // Callback fires during the stroke animation
78+
'ease': 'easeInOutExpo' // ease stroke individually
79+
'onStrokeStart': function(){console.log("Stroke started")}
80+
'onStrokeComplete': function(){console.log("Stroke completed")}
81+
'onStrokeUpdate': function(){console.log("Stroke update")}
8082
}, {
8183
'path': "M155.85,29c0...."
8284
'duration':1000
8385
}, {
8486
etc ...
8587
],
86-
'dimensions' : // dimensions of element
88+
'dimensions' : // dimensions of viewbox
8789
{
8890
'width': 270,
8991
'height':266
@@ -155,18 +157,4 @@ $('#demo').lazylinepainter('destroy');
155157
156158
## Author
157159
[http://camoconnell.com/](http://camoconnell.com/) <br>
158-
159-
160-
161-
162-
## Contributors
163-
Many thats to; <br>
164-
165-
- saeedseyfi / 0lumide
166-
* 1.6.1 additions
167-
168-
- [Jamie Perkins](http://inorganik.github.io)
169-
* 1.5.0 additions
170-
171-
- Matt Kemp
172-
* specify strokeWidth and strokeColor on a per-path basis.
160+

jquery.lazylinepainter-1.6.3.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
*/
1414

15+
1516
/*
1617
*
1718
* TERMS OF USE - EASING EQUATIONS
@@ -45,6 +46,7 @@
4546
*
4647
*/
4748

49+
4850
(function($) {
4951

5052
'use strict';
@@ -79,6 +81,7 @@
7981
'height': null,
8082

8183
'strokeWidth': 2,
84+
'strokeDash': null,
8285
'strokeColor': '#000',
8386
'strokeOverColor': null,
8487
'strokeCap': 'round',
@@ -160,7 +163,7 @@
160163
});
161164
};
162165

163-
el.style.strokeDasharray = length + ' ' + length;
166+
el.style.strokeDasharray = _getStrokeDashArray(path, options, length);
164167
el.style.strokeDashoffset = length;
165168
el.style.display = 'block';
166169
el.getBoundingClientRect();
@@ -620,6 +623,46 @@
620623
};
621624

622625

626+
/**
627+
* _getStrokeDashArray
628+
* @private
629+
*/
630+
var _getStrokeDashArray = function(path, options, length) {
631+
var strokeDash;
632+
if (path.strokeDash) {
633+
strokeDash = _getStrokeDashString(path.strokeDash, length);
634+
} else if (options.strokeDash) {
635+
strokeDash = _getStrokeDashString(options.strokeDash, length);
636+
} else {
637+
strokeDash = length + ' ' + length;
638+
};
639+
return strokeDash;
640+
};
641+
642+
643+
/**
644+
* _getStrokeDashString
645+
* @private
646+
*/
647+
var _getStrokeDashString = function(dashArray, length) {
648+
var strokeDashString = '';
649+
var strokeDashArray = dashArray.split(',');
650+
var strokeDashTotal = 0;
651+
var strokeDashNum;
652+
var strokeDashRemainder;
653+
for (var i = strokeDashArray.length - 1; i >= 0; i--) {
654+
strokeDashTotal += Number(strokeDashArray[i]);
655+
};
656+
strokeDashNum = Math.floor(length / strokeDashTotal);
657+
strokeDashRemainder = length - (strokeDashNum * strokeDashTotal);
658+
for (var i = strokeDashNum - 1; i >= 0; i--) {
659+
strokeDashString += (dashArray + ', ');
660+
};
661+
var preArray = strokeDashString + strokeDashRemainder + ', ' + length;
662+
return preArray.split(',').join('px,') + 'px';
663+
};
664+
665+
623666
/**
624667
* lazylinepainter
625668
* Extends jQuery's prototype object.

0 commit comments

Comments
 (0)