Created
October 4, 2012 21:08
-
-
Save johnferrie/3836468 to your computer and use it in GitHub Desktop.
CSS3 Filter Effects Sass Mixin
This file contains 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
// https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html | |
// | |
// grayscale ex: filter: grayscale(100%); | |
// sepia ex: filter: sepia(100%); | |
// saturate ex: filter: saturate(0%); | |
// hue-rotate ex: filter: hue-rotate(45deg); | |
// invert ex: filter: invert(100%); | |
// brightness ex: filter: brightness(15%); | |
// contrast ex: filter: contrast(200%); | |
// blur ex: filter: blur(2px); | |
=filter($filter-type,$filter-amount) | |
-webkit-filter: $filter-type+unquote('(#{$filter-amount})') | |
-moz-filter: $filter-type+unquote('(#{$filter-amount})') | |
-ms-filter: $filter-type+unquote('(#{$filter-amount})') | |
-o-filter: $filter-type+unquote('(#{$filter-amount})') | |
filter: $filter-type+unquote('(#{$filter-amount})') |
This file contains 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
// https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html | |
// | |
// grayscale ex: filter: grayscale(100%); | |
// sepia ex: filter: sepia(100%); | |
// saturate ex: filter: saturate(0%); | |
// hue-rotate ex: filter: hue-rotate(45deg); | |
// invert ex: filter: invert(100%); | |
// brightness ex: filter: brightness(15%); | |
// contrast ex: filter: contrast(200%); | |
// blur ex: filter: blur(2px); | |
@mixin filter($filter-type,$filter-amount) { | |
-webkit-filter: $filter-type+unquote('(#{$filter-amount})'); | |
-moz-filter: $filter-type+unquote('(#{$filter-amount})'); | |
-ms-filter: $filter-type+unquote('(#{$filter-amount})'); | |
-o-filter: $filter-type+unquote('(#{$filter-amount})'); | |
filter: $filter-type+unquote('(#{$filter-amount})'); | |
} | |
This file contains 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 { | |
-webkit-filter: grayscale(100%); | |
-moz-filter: greyacale(100%); | |
-ms-filter: grayscale(100%); | |
-o-filter: grayscale(100%); | |
filter: grayscale(100%); } |
This file contains 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 | |
+filter(grayscale,100%) |
This file contains 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 { | |
@include filter(grayscale, 100%); | |
} |
great! thank you!
👍
I like this a lot...
Many thanks!
Any chance to have it work with multiple filters at once? like
filter: grayscale(100%) blur(5px)
Thanks :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The SCSS version can not be used in Chrome. but the following code works: