jQuery & GSAP Based Modal Window with Motion Blur Effect

File Size: 2.67 KB
Views Total: 3555
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery & GSAP Based Modal Window with Motion Blur Effect

A stylish animated modal window with SVG filter based motion blur effect, built using jQuery, CSS3, SVG and GSAP JavaScript library (TweenMax.js).

How to use it:

1. Create a modal window that is hidden on page load.

<div class="modal">
  <button class="close-modal">×</button>
  <p>Modal Content</p>
</div>

2. Create a button to toggle the modal window.

<button class="open-modal">Open Modal</button>

3. Create a fullscreen overlay for the modal window.

<div class="modal-overlay"></div>

4. Create SVG elements for the motion blur effect. More information about SVG filters.

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="filters">
  <defs>
    <filter id="blur">
      <feGaussianBlur id="blur-filter" in="SourceGraphic" stdDeviation="0,0" />
    </filter>
  </defs>
</svg>

5. The essential CSS/CSS3 styles.

* { box-sizing: border-box; }

.modal-overlay {
  background: rgba(51,51,68,0.4);
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  opacity: 0;
  visibility: hidden;
}

.modal {
  background: #eeeaea;
  text-align: center;
  width: 230px;
  height: 320px;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  border-radius: 3px;
  margin: auto;
  padding: 20px;
  -webkit-filter: url("#blur");
  filter: url("#blur");
  -webkit-transform: translate3d(0, -900%, 0);
  transform: translate3d(0, -900%, 0);
}


.close-modal {
  background: none;
  border: none;
  position: absolute;
  font-size: 20px;
  right: 10px;
  top: 10px;
  color: #334;
  outline: none;
}

.filters {
  position: absolute;
  width: 0;
  height: 0;
}

6. Load the latest jQuery library and TweenMax.js at the bottom of your document..

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
<script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.15.0/TweenMax.min.js"></script> 

7. Enable the modal window and the motion blur effect.

$(document).ready(function(){
  var $obj=$(".modal")
  		  ,$overlay=$(".modal-overlay")
    ,blur=$("#blur-filter").get(0)
  ;
  
  function setBlur(v){
    blur.setAttribute("stdDeviation", v);
  }
  function getPos(){
    return $obj.position();
  }
  
  var lastPos=getPos();
  function update(){
    var pos=getPos();
    var limit=20;
    var dx=Math.min(limit,Math.abs(pos.left-lastPos.left)*0.5);
    var dy=Math.min(limit,Math.abs(pos.top-lastPos.top)*0.5);
    setBlur(dx+","+dy);
    
    lastPos=pos;
    requestAnimationFrame(update);
  }
  update();
  
  var isOpen=false;
  	function openModal(){
      /*$overlay.css({
        display:"block"
      })*/
      TweenMax.to($overlay,0.1,{autoAlpha:1});
      
      TweenMax.fromTo($obj,0.6,{y:-($(window).height()+$obj.height())},{delay:0.2,y:"0%",ease:Elastic.easeOut,easeParams:[1.1,0.7],force3D:true});
  }
  function closeModal(){
    TweenMax.to($overlay,0.1,{delay:0.55,autoAlpha:0});
    TweenMax.to($obj,0.55,{y:$(window).height()+$obj.height(),ease:Back.easeIn,force3D:true});
  }
  $(".open-modal").click(function(){
	    openModal();
  })
  $(".close-modal,.modal-overlay,.input-submit").click(function(){
    closeModal();
  })
  
})

This awesome jQuery plugin is developed by lbebber. For more Advanced Usages, please check the demo page or visit the official website.