Created
January 9, 2017 16:11
-
-
Save CassDucheseau/39343609be58ec77cfa16cef00b32162 to your computer and use it in GitHub Desktop.
Modal - With Video - Stop Video and Reset on Close
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| $('#modalOpen').on('click', function(){ | |
| $('.modal__containter').addClass('modal__open'); | |
| setTimeout(function(){ | |
| $('.modal').removeClass('hide'); | |
| $('.modal').addClass('transition'); | |
| }); | |
| setTimeout(function(){ | |
| $('.modal').removeClass('transition'); | |
| $('.modal').addClass('visible'); | |
| },50); | |
| }); | |
| $('.modal__close').on('click', function(){ | |
| var video = $("#playerid").attr("src"); | |
| $("#playerid").attr("src",""); | |
| $("#playerid").attr("src",video); | |
| $('.modal__containter').removeClass('modal__open'); | |
| $('.modal').removeClass('visible'); | |
| $('.modal').addClass('transition'); | |
| setTimeout(function(){ | |
| $('.modal').removeClass('transition'); | |
| $('.modal').addClass('hide'); | |
| },500); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .modal__containter { | |
| position: relative; | |
| &:before { | |
| } | |
| &.modal__open { | |
| overflow: hidden; | |
| &:before { | |
| content: ''; | |
| display: inline-block; | |
| background: rgba(0,0,0,0.5); | |
| position: fixed; | |
| top: -100%; | |
| bottom: 0; | |
| left: -100%; | |
| right: 0; | |
| z-index: 0; | |
| height: 200vh; | |
| width: 200vw; | |
| } | |
| } | |
| } | |
| .btn { | |
| text-decoration: none; | |
| color: black; | |
| background: white; | |
| text-transform: lowercase; | |
| font-family: helvetica; | |
| letter-spacing: 0.05em; | |
| font-size: 16px; | |
| padding: 10px 20px; | |
| display: inline-block; | |
| border: 3px solid black; | |
| } | |
| .modal { | |
| display: block; | |
| width: 500px; | |
| margin: 0 auto; | |
| text-align: center; | |
| border: 3px solid black; | |
| position: fixed; | |
| background: white; | |
| top: 60px; | |
| left: 0; | |
| right: 0; | |
| z-index: 1; | |
| -webkit-box-shadow: 3px 3px 20px 0px rgba(0,0,0,0.6); | |
| box-shadow: 3px 3px 20px 0px rgba(0,0,0,0.6); | |
| opacity: 0; | |
| transform: translateY(100px); | |
| transition: opacity 0.5s ease, transform 0.6s ease; | |
| &.visible { | |
| opacity: 1; | |
| transform: translateY(0); | |
| transition: opacity 0.5s ease, transform 0.6s ease; | |
| } | |
| &.transition { | |
| opacity: 0; | |
| transform: translateY(100px); | |
| transition: opacity 0.5s ease, transform 0.6s ease; | |
| } | |
| &.hide { | |
| display: none; | |
| } | |
| h3, | |
| p { | |
| font-family: helvetica; | |
| letter-spacing: 0.05em; | |
| } | |
| h3 { | |
| font-size: 26px; | |
| } | |
| p { | |
| font-size: 14px; | |
| margin-bottom: 10px; | |
| } | |
| iframe { | |
| margin-top: 30px; | |
| width: 100%; | |
| height: 230px; | |
| border: 6px solid black; | |
| } | |
| } | |
| .modal__content { | |
| padding: 50px 40px 30px; | |
| } | |
| .modal__close{ | |
| display: inline-block; | |
| position: absolute; | |
| top: 0; | |
| right: 0; | |
| padding: 15px; | |
| &:after { | |
| content: ''; | |
| display: inline-block; | |
| height: 100%; | |
| width: 100%; | |
| position: fixed; | |
| top: -100%; | |
| bottom: 0; | |
| left: -100%; | |
| right: 0; | |
| height: 200vh; | |
| width: 200vw; | |
| z-index: -1; | |
| } | |
| img { | |
| height: auto; | |
| width: 20px; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="#" class="btn" id="modalOpen">Open Modal</a> | |
| <div class="modal__containter"> | |
| <div class="modal hide"> | |
| <a href="#" class="modal__close"><img src="http://image.flaticon.com/icons/png/128/61/61155.png"></a> | |
| <div class="modal__content"> | |
| <h3>This is a Modal With a Video</h3> | |
| <iframe id="playerid" width="560" height="315" src="https://www.youtube.com/embed/9GHPNKUMf70?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe> | |
| </div> | |
| </div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| View Code Pen: | |
| http://codepen.io/DinosVsRobots/pen/RKWxvJ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment