Created
October 16, 2008 17:00
-
-
Save staaky/17204 to your computer and use it in GitHub Desktop.
Cross browser way to set a PNG background image on an element using Prototype.
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
Element.addMethods({ | |
setPngBackground: (function() { | |
var IEBelow7 = (function(agent) { | |
var version = new RegExp('MSIE ([\\d.]+)').exec(agent); | |
return version ? parseFloat(version[1]) < 7 : false; | |
})(navigator.userAgent); | |
return function(element, url) { | |
element = $(element); | |
var options = Object.extend({ | |
align: 'top left', | |
repeat: 'no-repeat', | |
sizingMethod: 'scale', | |
backgroundColor: '' | |
}, arguments[2] || {}); | |
element.setStyle(IEBelow7 ? { | |
filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + url + '\'\', sizingMethod=\'' + | |
options.sizingMethod + '\')' | |
} : { | |
background: options.backgroundColor + ' url(' + url + ') ' + options.align + ' ' + options.repeat | |
}); | |
return element; | |
} | |
})() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment