我有以下功能可以处理,但不是点击 #featured li.block div 来进行div旋转;如何使用班级按钮 a.button 建立链接?可点击以使 #featured li.block div divs spin?
$('#featured li.block div').click(function()
{
var f = function($this, count)
{
$this.animate({
top: "-=200"
}, 70, function() {
$this.css('top', '220px').animate({
top: "-=220"
}, 70, function() {
if (count > 0) {
count = count - 1;
f($this, count);
/*if(count == 0) {
if ($this.hasClass('showing')) {
$this.removeClass('showing').addClass('hiding').hide();
}
}*/
}
});
});
};
f($(this), 8);
});
答案 0 :(得分:2)
使用a.button
作为单击处理程序的选择器和函数调用的原始选择器。
编辑无论具有多个内部DIV的选择器,我都无法使您的代码正常工作。试试这个(奖金,它更简单):
$('a.button').click(function()
{
var f = function($this, count)
{
$this.animate({
top: "-=200"
}, 70, function() {
$this.css('top', '220px').animate({
top: "-=220"
}, 70, function() {
if (count > 0) {
f($this, --count);
}
});
});
};
$('#featured li.block div').each( function(i) {
var $this = $(this);
setTimeout( function() {
f( $this, 8 );
}, i*100 ); // the ith div will start in i*100ms
});
});