我有一套div-s,我需要应用一些jQuery。为什么变量不会传递?
<div id="anim1" class="animation"></div>
<div id="anim2" class="animation"></div>
它看起来很直接,但我想让它更灵活一点。虽然... ...可能是不可能的,但是我没有复制和粘贴jQuery函数多少次,我想知道是否有任何方式从mouseover动作中获取图层名称并将其放入一个变量,我可以在以下脚本中使用:
$(document).ready(function() {
$('.animation').mouseover(function() {
layer = '#'+this.id;
});
var steps = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, 1550, 1600, 1650, 1700, 1750, 1800, 1850, 1900, 1950, 2000, 2050, 2100, 2150, 2200, 2250, 2300, 2350, 2400, 2450, 2500, 2550, 2600, 2650, 2700, 2750, 2800, 2850, 2900, 2950,];
var index = -1;
setTimeout(function() {
index++;
if(index == 57) {
index = 0;
}
$(layer).hover(function(){
index ++;
}, function(){
index -=1;
});
$(layer).css('backgroundPosition', '-' + steps[index] + 'px 0px');
setTimeout(arguments.callee, 50);
}, 25);
});
我想知道我在做什么错在这里。任何想法都非常感谢...
更新。试图在$(document).ready(function()中声明变量。我不确定是否可以这样做,但至少动画现在正在移动。唯一的问题是,当我
$(document).ready(function() {
layer = $('.animation').mouseover(function() {
'#'+this.id;
});
对于其中一个,'*'不是变量名的有效字符。 –
@Asad看起来像他想要加粗变量名称 – VIDesignz
是的,我想要粗体显示变量名称以便能够更好地看到 – Perren