Created
December 7, 2017 16:20
-
-
Save salt-istanbul/c1686c9f69990dc202fefe608ec3b10f to your computer and use it in GitHub Desktop.
SASS/SCSS mixin for filter transition
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
img.lazy{ | |
@include filter(blur, 30px); | |
&.lazy-loaded{ | |
@include filter(blur, 0px); | |
@include transition(filter .5s ease-out); | |
} | |
} |
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
@mixin filter($filter, $value) { | |
-webkit-filter: $filter+unquote('(#{$value})'); | |
-moz-filter: $filter+unquote('(#{$value})'); | |
-ms-filter: $filter+unquote('(#{$value})'); | |
-o-filter: $filter+unquote('(#{$value})'); | |
filter: $filter+unquote('(#{$value})'); | |
} | |
@mixin transition($transition...) { | |
@if str-index(quote($transition), "filter")==1 { | |
-moz-transition: unquote(str-insert(quote($transition),"-moz-",1)); | |
-o-transition: unquote(str-insert(quote($transition),"-o-",1)); | |
-webkit-transition: unquote(str-insert(quote($transition),"-webkit-",1)); | |
transition: $transition; | |
} @else { | |
-moz-transition: $transition; | |
-o-transition: $transition; | |
-webkit-transition: $transition; | |
transition: $transition; | |
} | |
} |
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
img.img-lazy { | |
-webkit-filter: blur(30px); | |
-moz-filter: blur(30px); | |
-ms-filter: blur(30px); | |
-o-filter: blur(30px); | |
filter: blur(30px); | |
} | |
img.img-lazy.lazy-loaded { | |
-webkit-filter: blur(0px); | |
-moz-filter: blur(0px); | |
-ms-filter: blur(0px); | |
-o-filter: blur(0px); | |
filter: blur(0px); | |
-moz-transition: -moz-filter 0.5s ease-out; | |
-o-transition: -o-filter 0.5s ease-out; | |
-webkit-transition: -webkit-filter 0.5s ease-out; | |
transition: filter 0.5s ease-out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment