为什么这个jquery简单的传输效果不起作用?

时间:2014-05-08 01:08:43

标签: javascript jquery html css

 $(function () {
    $("#div1").click(function () {
        $(this).effect("transfer", { to: $("#div2") }, 1000);
        //$(this).effect("shake", { times: 2 }, 200);
    });
});

“摇晃”效果可行,但转移不起作用,如何解决问题?

2 个答案:

答案 0 :(得分:0)

请尝试以下格式:

<script>
$( "div" ).click(function() {
var i = 1 - $( "div" ).index( this );
$( this ).effect( "transfer", { to: $( "div" ).eq( i ) }, 1000 );
});
</script>

您可能遗漏了一些部分,例如var i的角色。

答案 1 :(得分:0)

您的代码看起来很好。

确保您的DOM上有两个具有相应ID的div。还要确保你在CSS中定义了一个ui-effects-transfer类,因为缺少这个会使你的事件看起来像什么都没有。

看到这个小提琴: http://jsfiddle.net/r4RTH/

HTML:

<div id="div1" class="green"></div>
<div id="div2" class="red"></div>

JS:

 $("#div1").click(function () {
     $(this).effect("transfer", { to: $("#div2") }, 1000);
     $(this).effect("shake", { times: 2 }, 200);
 });

$( "#div2" ).click(function() {
    $( this ).effect( "transfer", { to: $( "#div1" ) }, 1000 );
    $(this).effect("shake", { times: 2 }, 200);
});

CSS:

div.green {
    width: 100px;
    height: 80px;
    background: green;
    border: 1px solid black;
    position: relative;
}

div.red {
    margin-top: 10px;
    width: 50px;
    height: 30px;
    background: red;
    border: 1px solid black;
    position: relative;
}

.ui-effects-transfer {
    background-color: black
}
相关问题