a.css() jquery,javascript - Getting a CSS value from $(this) in jQuery - Stack Overflow

So I have working code that animates a BG image via a plugin. This is a general solution though where each element in the class has the same BG image; I'm using a sprite with a unique image for each column of my navigation bar. THe code is thusly:

$('#nav a')

.mouseover(function(){

$(this).stop().animate(

{backgroundPosition:"(0 -250px)"},

{duration:500})

})

.mouseout(function(){

$(this).stop().animate(

{backgroundPosition:"(0 0)"},

{duration:500})

})

This works great, so I can set a Y-offset for each element, but each link has it's own x-offset that won't change/be animated at all. Example CSS:

li.downloads a {

background:url(img/navsprite.png) repeat -318px -9px;

}

I want to roll the -318px -9px to something like -318px 200px, but for another element I'd want to change -482px -9px to -482px 200px. Only the Y-offset should change, but I don't know the syntax of jQuery well enough to pull that value from the CSS of $(this) element and put it into the animate parameters. Thanks!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值