Skip to content

Instantly share code, notes, and snippets.

@cocopon
Last active December 21, 2015 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocopon/6341356 to your computer and use it in GitHub Desktop.
Save cocopon/6341356 to your computer and use it in GitHub Desktop.
Sass transparent color function for legacy IE (<= 8)
module Sass::Script::Functions
def ms_filter_rgba(*args)
if args.size == 4
red, green, blue, alpha = args
return ms_rgba(rgb(red, green, blue), alpha)
end
if args.size != 2
raise ArgumentError.new("wrong number of arguments (#{args.size} for 2 or 4")
end
color, alpha = args
assert_type color, :Color, :color
assert_type alpha, :Number, :alpha
Sass::Util.check_range('Alpha channel', 0..1, alpha)
hex = '#%02x%02x%02x%02x' % [
alpha.value * 255,
color.red,
color.green,
color.blue]
retval = "progid:DXImageTransform.Microsoft.gradient(startColorStr='#{hex}', endColorStr='#{hex}')"
return Sass::Script::String.new(retval)
end
declare :ms_filter_rgba, [:red, :green, :blue, :alpha]
declare :ms_filter_rgba, [:color, :alpha]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment