使用脚本动画单击功能

时间:2012-11-30 12:31:19

标签: javascript jquery html

除了动画点击功能外,一切正常。

我想在点击时设置动画背景。
我知道我可以在html中执行div标记并调用它,但它不是我想要的。

有人可以告诉我如何在脚本中完成它吗?

if (numbers[i] == 1){
    $('<div>1</div>').css({
            background: "url(img/1.png)", 
            'background-size': '100% 100%', 
            'background-repeat': 'no-repeat'
        })
        .data( 'number', numbers[i] )
        .attr( 'id', 'card'+numbers[i] )
        .appendTo( '#cardPile' + pile[i] ).draggable({
            containment: '#content',
            stack: '#cardPile1 div',
            cursor: 'move',
        })
        .click(function(){
            $('<div>1</div>').animate({
                height:'181px', 
                width:'169px', 
                top: '-30', 
                left: '-20', opacity: '0.4'
            }, 1000)
        });
}

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

当您点击第一个div时,您会创建第二个:

$('<div>1</div>').animate({....

也许你想在动画中使用相同的东西?

$(this).animate({...

答案 1 :(得分:0)

您需要append这样的div

$('<div>1</div>').animate({
      height:'181px',
      width:'169px',
      top: '-30', 
      left: '-20', 
      opacity: '0.4'}
   , 1000).appendTo('body');