`

jquery 在firefox下不支持backgroundPositionY

阅读更多
引用

在firefox下jquery的css方法不支持backgroundPositionY属性,
我们可以通过如下方法解决。


(function($) {

var div = document.createElement('div'),
    rposition = /([^ ]*) (.*)/;
  
if(div.style.backgroundPositionX !== '') {
  	$(['X', 'Y']).each(function( i, letter ) {
    	var property = 'backgroundPosition' + letter,
      		isX = letter == 'X';
    	$.cssHooks[property] = {
      		set: function(elem, value) {
        		var current = elem.style.backgroundPosition;
        		elem.style.backgroundPosition = (isX? value + ' ' : '' ) + (current? current.match(rposition)[isX+1] : '0') + (isX? '' : ' ' + value);
      		},
      		get: function(elem, computed) {
        		var current = computed?
          			$.css(elem, 'backgroundPosition') :
          			elem.style.backgroundPosition;
        		return current.match(rposition)[!isX+1];
      		}
    	};
    	$.fx.step[property] = function(fx) {
      		$.cssHooks[property].set(fx.elem, fx.now + fx.unit);
    	}
  	});
}
div = null;

})(jQuery);


引用

https://github.com/louisremi/jquery.backgroundXY.js/blob/master/jquery.backgroundXY.js
https://github.com/brandonaaron/jquery-cssHooks/blob/master/bgpos.js
分享到:
评论
2 楼 lzfsuru250 2014-01-20  
     写好插件了要怎么用呢?
1 楼 guduxing890 2013-12-17  
多谢。 解决了我一个兼容性问题。

相关推荐

Global site tag (gtag.js) - Google Analytics