A Pen by Dejan Babić on CodePen.
Created
June 6, 2020 23:13
-
-
Save melanyss/26ff2e58ff80e76bee587869a783f7b2 to your computer and use it in GitHub Desktop.
Animating a gif on hover
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
| <div class="gif"> | |
| <div class="gif__item" data-gif-trigger> | |
| <figure> | |
| <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1528105/cover.jpg" data-gif-image="https://media.giphy.com/media/3ov9jQWd5qhiUSPDri/giphy.gif" data-image="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1528105/cover.jpg" alt=""> | |
| </figure> | |
| <h2>Hover me</h2> | |
| </div> | |
| </div> | |
| <div class="link"> | |
| <a href="https://codepen.io/microfront/pens/public/" target="_blank"> <span class="fa fa-codepen"></span>my other Pens</a> | |
| </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
| $(document).on( | |
| { | |
| mouseenter: function() { | |
| var gifImage = $(this).find("img"), | |
| gifImageSrc = gifImage.data("gif-image"); | |
| gifImage.attr("src", gifImageSrc); | |
| }, | |
| mouseleave: function() { | |
| var gifImage = $(this).find("img"), | |
| coverSrc = gifImage.data("image"); | |
| gifImage.attr("src", coverSrc); | |
| } | |
| }, | |
| "[data-gif-trigger]" | |
| ); |
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
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> |
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
| *, | |
| :after, | |
| :before { | |
| box-sizing: border-box; | |
| } | |
| .gif { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100vh; | |
| background: rgb(111, 42, 209); | |
| background: -moz-linear-gradient( | |
| -45deg, | |
| rgba(111, 42, 209, 1) 28%, | |
| rgba(246, 90, 173, 1) 100% | |
| ); | |
| background: -webkit-linear-gradient( | |
| -45deg, | |
| rgba(111, 42, 209, 1) 28%, | |
| rgba(246, 90, 173, 1) 100% | |
| ); | |
| background: linear-gradient( | |
| 135deg, | |
| rgba(111, 42, 209, 1) 28%, | |
| rgba(246, 90, 173, 1) 100% | |
| ); | |
| filter: progid:DXImageTransform.Microsoft.gradient( | |
| startColorstr="#6f2ad1", | |
| endColorstr="#f65aad", | |
| GradientType=1 | |
| ); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| padding: 60px; | |
| @media only screen and (max-width: 800px) { | |
| padding: 40px; | |
| } | |
| &__item { | |
| width: 100%; | |
| max-width: 600px; | |
| background-color: #fff; | |
| box-shadow: 0px 0px 41px rgba(0, 0, 0, 0.6); | |
| position: relative; | |
| cursor: pointer; | |
| transition: all 0.6s cubic-bezier(0.13, 1.07, 0.84, 1); | |
| @media only screen and (max-width: 960px) { | |
| max-width: 550px; | |
| } | |
| &:after { | |
| content: ""; | |
| position: absolute; | |
| left: 0; | |
| top: 0; | |
| width: 100%; | |
| height: 100%; | |
| background-color: rgba(0, 0, 0, 0.5); | |
| transition: all 0.6s cubic-bezier(0.13, 1.07, 0.84, 1); | |
| } | |
| &:hover { | |
| box-shadow: 0px 0px 51px rgba(0, 0, 0, 0.6); | |
| &:after { | |
| opacity: 0; | |
| } | |
| h2 { | |
| transform: translate(123px, 96px); | |
| opacity: 0; | |
| @media only screen and (max-width: 960px) { | |
| transform: translate(83px, 70px); | |
| } | |
| @media only screen and (max-width: 800px) { | |
| transform: translate(33px, 50px); | |
| } | |
| } | |
| } | |
| figure { | |
| position: relative; | |
| padding-bottom: 56.16%; | |
| overflow: hidden; | |
| margin: 0; | |
| } | |
| h2 { | |
| color: #f659ae; | |
| position: absolute; | |
| right: 0; | |
| bottom: 0; | |
| transform: translate(82px, 46px); | |
| font-size: 90px; | |
| line-height: 90px; | |
| font-family: "Roboto", sans-serif; | |
| font-weight: 900; | |
| text-transform: uppercase; | |
| letter-spacing: -4px; | |
| margin: 0; | |
| text-shadow: 0px 0px 30px rgba(0, 0, 0, 0.6); | |
| z-index: 1; | |
| transition: all 0.45s cubic-bezier(0.13, 1.07, 0.84, 1); | |
| @media only screen and (max-width: 960px) { | |
| font-size: 80px; | |
| line-height: 80px; | |
| transform: translate(71px, 41px); | |
| transition: all 0.35s cubic-bezier(0.13, 1.07, 0.84, 1); | |
| } | |
| @media only screen and (max-width: 800px) { | |
| font-size: 10vw; | |
| transform: translate(22px, 41px); | |
| transition: all 0.25s cubic-bezier(0.13, 1.07, 0.84, 1); | |
| } | |
| } | |
| img { | |
| bottom: -9999px; | |
| height: 100%; | |
| left: -9999px; | |
| margin: auto; | |
| max-width: none; | |
| min-width: 100%; | |
| position: absolute; | |
| right: -9999px; | |
| top: -9999px; | |
| width: auto; | |
| } | |
| } | |
| } | |
| .link { | |
| position: absolute; | |
| left: 0; | |
| bottom: 0; | |
| padding: 20px; | |
| z-index: 9999; | |
| a { | |
| display: flex; | |
| align-items: center; | |
| text-decoration: none; | |
| color: #fff; | |
| } | |
| .fa { | |
| font-size: 28px; | |
| margin-right: 8px; | |
| color: #fff; | |
| } | |
| } |
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
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment