jquery设置动态背景和悬停不处理某些问题
我有一个很大的精灵图像,我只是把这个图像作为背景设置为我的30张李的背景。设置背景后,在悬停时,我只想减去y位置到70px,这样它就会到达背景上方 对于这个,我正在检索当前的x,y并存储,从y开始,我只是减少70px以达到我的悬停位置,但是我没有得到正确的结果。它可以工作,但它非常有缺陷,有人能纠正我的代码以更好地工作吗 我的代码:jquery设置动态背景和悬停不处理某些问题,jquery,facebook,Jquery,Facebook,我有一个很大的精灵图像,我只是把这个图像作为背景设置为我的30张李的背景。设置背景后,在悬停时,我只想减去y位置到70px,这样它就会到达背景上方 对于这个,我正在检索当前的x,y并存储,从y开始,我只是减少70px以达到我的悬停位置,但是我没有得到正确的结果。它可以工作,但它非常有缺陷,有人能纠正我的代码以更好地工作吗 我的代码: $('.logo-gal li').each(function(index){ // dynamically i am setting the bg, works.
$('.logo-gal li').each(function(index){ // dynamically i am setting the bg, works.
index % 5 == 0 ? y+=1 : y;
$(this).css({
background:'url(images/css/gall-logo.png) no-repeat',
backgroundPosition: -((index%5) * 106)+'px '+ -(y*140) +'px'
})
})
$('.logo-gal li').hover(function(){
var backPos = $(this).css('backgroundPosition').split(" ");
var xPos = parseInt(backPos[0]),yPos = parseInt(backPos[1]);//storing x y pos.
console.log(xPos);
$(this).css({backgroundPosition: xPos+ (yPos-70)+"px"});// applying too.. not work, and i need to setback the stored dada, while mouseout..
})
有什么好建议吗?您在字符串癌变方面有问题
$('.logo-gal li').each(function(index){ // dynamically i am setting the bg, works.
index % 5 == 0 ? y+=1 : y;
$(this).css({
background:'url(images/css/gall-logo.png) no-repeat',
backgroundPosition: '-'+eval((index%5) * 106)+'px -'+eval(y*140) +'px'
})
})
$('.logo-gal li').hover(function(){
var backPos = $(this).css('backgroundPosition').split(" ");
var xPos = parseInt(backPos[0]),yPos = parseInt(backPos[1]);//storing x y pos.
console.log(xPos);
$(this).css({backgroundPosition: eval(xPos+ yPos)+"px"});// applying too.. not work, and i need to setback the stored dada, while mouseout..
})
什么是“30个李的背景”?为什么不使用
.length
而不是使用'5'。我有30个'li'元素。。每个5将是一行,所以我使用5!