@@ -18,6 +18,8 @@ var Ripple = {
18
18
19
19
function rippler ( event , el ) {
20
20
var target = el ;
21
+ // Get border to avoid offsetting on ripple container position
22
+ var targetBorder = parseInt ( ( getComputedStyle ( target ) . borderWidth ) . replace ( 'px' , '' ) ) ;
21
23
22
24
// Get necessary variables
23
25
var rect = target . getBoundingClientRect ( ) ,
@@ -30,11 +32,14 @@ var Ripple = {
30
32
maxX = Math . max ( dx , width - dx ) ,
31
33
maxY = Math . max ( dy , height - dy ) ,
32
34
style = window . getComputedStyle ( target ) ,
33
- radius = Math . sqrt ( ( maxX * maxX ) + ( maxY * maxY ) ) ;
35
+ radius = Math . sqrt ( ( maxX * maxX ) + ( maxY * maxY ) ) ,
36
+ border = ( targetBorder > 0 ) ? targetBorder : 0 ;
34
37
35
38
// Create the ripple and its container
36
39
var ripple = document . createElement ( "div" ) ,
37
40
rippleContainer = document . createElement ( "div" ) ;
41
+ rippleContainer . className = 'ripple-container' ;
42
+ ripple . className = 'ripple' ;
38
43
39
44
//Styles for ripple
40
45
ripple . style . marginTop = '0px' ;
@@ -50,21 +55,29 @@ var Ripple = {
50
55
51
56
//Styles for rippleContainer
52
57
rippleContainer . style . position = 'absolute' ;
53
- rippleContainer . style . left = '0 ';
54
- rippleContainer . style . top = '0 ';
58
+ rippleContainer . style . left = 0 - border + 'px ';
59
+ rippleContainer . style . top = 0 - border + 'px ';
55
60
rippleContainer . style . height = '0' ;
56
61
rippleContainer . style . width = '0' ;
57
62
rippleContainer . style . pointerEvents = 'none' ;
58
63
rippleContainer . style . overflow = 'hidden' ;
59
64
65
+ // Store target position to change it after
66
+ var storedTargetPosition = ( ( target . style . position ) . length > 0 ) ? target . style . position : getComputedStyle ( target ) . position ;
67
+ // Change target position to relative to guarantee ripples correct positioning
68
+ if ( storedTargetPosition !== 'relative' ) {
69
+ target . style . position = 'relative' ;
70
+ }
71
+
60
72
rippleContainer . appendChild ( ripple ) ;
61
- document . body . appendChild ( rippleContainer ) ;
73
+ target . appendChild ( rippleContainer ) ;
62
74
63
75
ripple . style . marginLeft = dx + "px" ;
64
76
ripple . style . marginTop = dy + "px" ;
65
77
66
- rippleContainer . style . left = left + ( ( ( window . pageXOffset || document . scrollLeft ) - ( document . clientLeft || 0 ) ) || 0 ) + "px" ;
67
- rippleContainer . style . top = top + ( ( ( window . pageYOffset || document . scrollTop ) - ( document . clientTop || 0 ) ) || 0 ) + "px" ;
78
+ // No need to set positioning because ripple should be child of target and to it's relative position.
79
+ // rippleContainer.style.left = left + (((window.pageXOffset || document.scrollLeft) - (document.clientLeft || 0)) || 0) + "px";
80
+ // rippleContainer.style.top = top + (((window.pageYOffset || document.scrollTop) - (document.clientTop || 0)) || 0) + "px";
68
81
rippleContainer . style . width = width + "px" ;
69
82
rippleContainer . style . height = height + "px" ;
70
83
rippleContainer . style . borderTopLeftRadius = style . borderTopLeftRadius ;
@@ -92,6 +105,27 @@ var Ripple = {
92
105
} , 850 ) ;
93
106
94
107
el . removeEventListener ( 'mouseup' , clearRipple , false ) ;
108
+
109
+ // After removing event set position to target to it's original one
110
+ // Timeout it's needed to avoid jerky effect of ripple jumping out parent target
111
+ setTimeout ( function ( ) {
112
+
113
+ var clearPosition = true ;
114
+ for ( var i = 0 ; i < target . childNodes . length ; i ++ ) {
115
+ if ( target . childNodes [ i ] . className === 'ripple-container' ) {
116
+ clearPosition = false ;
117
+ }
118
+ }
119
+
120
+ if ( clearPosition ) {
121
+ if ( storedTargetPosition !== 'static' ) {
122
+ target . style . position = storedTargetPosition ;
123
+ } else {
124
+ target . style . position = '' ;
125
+ }
126
+ }
127
+
128
+ } , props . transition + 250 )
95
129
}
96
130
97
131
if ( event . type === 'mousedown' ) {
0 commit comments