Created
April 17, 2018 10:44
-
-
Save DevShahidul/ecb7b2485e1cf5a76ac96f38c9d7af53 to your computer and use it in GitHub Desktop.
See example Here >>> https://codepen.io/ibanez182/pen/LZPgrY
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
| <h1><small>Fullscreen</small> Ken Burns effect <small>without javascript</small></h1> | |
| <!-- You can add more ".slideshow-image" elements, but remember to update the "$items" variable on SCSS --> | |
| <div class="slideshow"> | |
| <div class="slideshow-image" style="background-image: url('https://source.unsplash.com/category/nature/1600x1400')"></div> | |
| <div class="slideshow-image" style="background-image: url('https://source.unsplash.com/category/buildings/1600x1400')"></div> | |
| <div class="slideshow-image" style="background-image: url('https://source.unsplash.com/category/food/1600x1400')"></div> | |
| <div class="slideshow-image" style="background-image: url('https://source.unsplash.com/category/technology/1600x1400')"></div> | |
| </div> | |
| <style> | |
| $items: 4; | |
| $animation-time: 4s; | |
| $transition-time: .5s; | |
| $scale: 20%; | |
| $total-time: ($animation-time * $items); | |
| $scale-base-1: (1 + $scale / 100%); | |
| .slideshow { | |
| position: absolute; | |
| width: 100vw; | |
| height: 100vh; | |
| overflow: hidden; | |
| } | |
| .slideshow-image { | |
| position: absolute; | |
| width: 100%; | |
| height: 100%; | |
| background: no-repeat 50% 50%; | |
| background-size: cover; | |
| animation-name: kenburns; | |
| animation-timing-function: linear; | |
| animation-iteration-count: infinite; | |
| animation-duration: $total-time; | |
| opacity: 1; | |
| transform: scale($scale-base-1); | |
| @for $i from 1 through $items { | |
| &:nth-child(#{$i}) { | |
| animation-name: kenburns-#{$i}; | |
| z-index: ($items - $i); | |
| } | |
| } | |
| } | |
| @for $i from 1 through $items { | |
| @keyframes kenburns-#{$i} { | |
| $animation-time-percent: percentage($animation-time / $total-time); | |
| $transition-time-percent: percentage($transition-time / $total-time); | |
| $t1: ($animation-time-percent * ($i - 1) - $transition-time-percent / 2); | |
| $t2: ($animation-time-percent * ($i - 1) + $transition-time-percent / 2); | |
| @if($t1 < 0%) { $t1: 0%; } | |
| @if($t2 < 0%) { $t2: 0%; } | |
| $t3: ($animation-time-percent * ($i) - $transition-time-percent / 2); | |
| $t4: ($animation-time-percent * ($i) + $transition-time-percent / 2); | |
| @if($t3 > 100%) { $t3: 100%; } | |
| @if($t4 > 100%) { $t4: 100%; } | |
| $t5: (100% - $transition-time-percent / 2); | |
| $t6: (($t4 - $t1) * 100% / $t5); | |
| #{$t1} { opacity: 1; transform: scale($scale-base-1); } | |
| #{$t2} { opacity: 1; } | |
| #{$t3} { opacity: 1; } | |
| #{$t4} { opacity: 0; transform: scale(1); } | |
| @if($i != $items) { | |
| 100% { opacity: 0; transform: scale($scale-base-1); } | |
| } | |
| @if($i == 1) { | |
| $scale-plus: ($scale * (100% - $t5) / $t4); | |
| $scale-plus-base-1: (1 + ($scale + $scale-plus) / 100%); | |
| #{$t5} { opacity: 0; transform: scale($scale-plus-base-1); } | |
| 100% { opacity: 1; } | |
| } | |
| } | |
| } | |
| // Presentational stuff | |
| h1 { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate3d(-50%, -50%, 0); | |
| z-index: 99; | |
| text-align: center; | |
| font-family: Raleway, sans-serif; | |
| font-weight: 300; | |
| text-transform: uppercase; | |
| background-color: rgba(255,255,255,.75); | |
| box-shadow: 0 1em 2em -1em rgba(0,0,0,.5); | |
| padding: 1em 2em; | |
| line-height: 1.5; | |
| small { | |
| display: block; | |
| text-transform: lowercase; | |
| font-size: .7em; | |
| &:first-child { | |
| border-bottom: 1px solid rgba(0,0,0,.25); | |
| padding-bottom: .5em; | |
| } | |
| &:last-child { | |
| border-top: 1px solid rgba(0,0,0,.25); | |
| padding-top: .5em; | |
| } | |
| } | |
| } | |
| </style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment