This time I will share jQuery Plugin and tutorial about Elastic SVG Modal Window with jQuery and Snap.svg, hope it will help you in programming stack.
A fancy elastic morphing modal window with SVG shape animations built on top of jQuery and Snap.svg. Inspired by codrops’ Elastic SVG Elements.
How to use it:
1. Include the necessary jQuery and Snap.SVG javascript libraries on the html page.
1 |
< script src = "/path/to/jquery-2.1.4.min.js" ></ script > |
2 |
< script src = "/path/to/snap.svg-min.js" ></ script > |
2. Create a SVG modal window with a close button as follow.
01 |
< div id = "modal" class = "modal" > |
02 |
< button id = "modal-close" class = "modal-close" >Close</ button > |
03 |
< div id = "svg-wrapper" class = "svg-wrapper" data-btn-hovered="M1220.267,723.2c0,0-293.547,0-580.267,0c-333.653,0-584.533,0-584.533,0s0-104.783,0-334.854 |
04 |
c0-188.981,0-334.846,0-334.846s251.733,0,584.533,0c362.667,0,580.267,0,580.267,0s0,116.7,0,344.803 |
05 |
C1220.267,613.127,1220.267,723.2,1220.267,723.2L1220.267,723.2" data-modal-open="M1220.267,723.2c0,0-292.456-47.624-579.176-47.624c-333.653,0-585.624,47.624-585.624,47.624 |
06 |
s83.149-104.783,83.149-334.854c0-188.981-83.149-334.846-83.149-334.846s251.324,49.105,584.124,49.105 |
07 |
c362.667,0,580.676-49.105,580.676-49.105s-72.201,123.987-72.201,352.09C1148.065,620.414,1220.267,723.2,1220.267,723.2 |
10 |
< svg id = "svg" width = "100%" height = "100%" viewBox = "0 0 1280 800" preserveAspectRatio = "none" > |
11 |
< path id = "svg-path" d="M1220.267,723.2c0,0-293.547,0-580.267,0c-333.653,0-584.533,0-584.533,0s0-3.505,0-11.2 |
12 |
c0-6.321,0-11.2,0-11.2s251.733,0,584.533,0c362.667,0,580.267,0,580.267,0s0,3.903,0,11.533 |
13 |
C1220.267,719.519,1220.267,723.2,1220.267,723.2L1220.267,723.2" /> |
3. Create a link to launch the modal window.
1 |
< a href = "#" class = "btn btn-show-overlay" >Lauch a modal</ a > |
4. The core CSS styles.
26 |
-webkit-transition: height 0.6 s, width 0.6 s; |
27 |
transition: height 0.6 s, width 0.6 s; |
33 |
text-transform : uppercase ; |
39 |
background-color : transparent ; |
40 |
border-bottom : 2px solid transparent ; |
43 |
.modal-close:hover, .modal-close:focus { border-bottom-color : white ; } |
45 |
.modal-active .modal { |
50 |
.modal-active .btn { display : none ; } |
52 |
.modal-active .modal-close { display : block ; } |
5. The JavaScript to active the modal window.
03 |
showOverlay: $( '.btn-show-overlay' ), |
04 |
closeOverlay: $( '#modal-close' ), |
06 |
svgWrapper: $( '#svg-wrapper' ), |
07 |
pathElement: undefined, |
11 |
default: $( '#svg-path' ). attr ( 'd' ), |
12 |
active: $( '#svg-wrapper' ).data( 'btn-hovered' ), |
13 |
modalOpen: $( '#svg-wrapper' ).data( 'modal-open' ) |
17 |
svgModal.pathElement = s.select( 'path' ); |
21 |
svgModal.showOverlay.on( 'mouseenter' , this.btnHover); |