为什么这个jquery简单的传输效果不工作

Why does this jquery simple transfer effect not work?

本文关键字:工作 传输 jquery 简单 为什么      更新时间:2023-09-26
 $(function () {
    $("#div1").click(function () {
        $(this).effect("transfer", { to: $("#div2") }, 1000);
        //$(this).effect("shake", { times: 2 }, 200);
    });
});

"摇"的效果是可以的,但是transfer不可以,如何解决这个问题?

试试这个格式:

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

你可能错过了一些部分,比如var i的角色。

你的代码看起来不错。

确保你有两个div,它们各自的id在你的DOM上。还要确保在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
}