如何获得firefox中使用jQuery的background-position-y? [英] How do I get the background-position-y in firefox using jQuery?

查看:123
本文介绍了如何获得firefox中使用jQuery的background-position-y?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(elem).css('backgroundPositionY')



<在铬,即safari,而不是Firefox(也不是我相信的歌剧)。你会认为jQuery会有一个polyfill,但是它没有,从1.5开始。我怎样才能轻松获得背景Y的位置,例如背景动画(例如视差)?

编辑告诉Mozilla 你想要 background-position- [x,y] 支持。 (使用投票功能,而不是评论,除非你有先见之明添加)。 Bug自2010年以来(3年)开放,所以不要屏住呼吸。 :)

解决方案

  var backgroundPos = $(elem).css('backgroundPosition') 。分裂( ); 
//现在包含一个数组,如[0%,50px]

var xPos = backgroundPos [0],
yPos = backgroundPos [1];


$(elem).css('backgroundPositionY')

does it on chrome, ie, and safari, but not Firefox (nor Opera I believe). You'd think jQuery would have a polyfill but it doesn't, as of 1.5. How can I easily get the background Y position for e.g. background animations (for e.g. parallax)?

EDIT: Tell Mozilla you want background-position-[x,y] support. (use the "vote" feature, not comment, unless you have something prescient to add). Bug has been open since 2010 tho (3 years now) so don't hold your breath for a fix. :)

解决方案

var backgroundPos = $(elem).css('backgroundPosition').split(" ");
//now contains an array like ["0%", "50px"]

var xPos = backgroundPos[0],
    yPos = backgroundPos[1];

这篇关于如何获得firefox中使用jQuery的background-position-y?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆