[英]Why does this jquery simple transfer effect not work?
$(function () {
$("#div1").click(function () {
$(this).effect("transfer", { to: $("#div2") }, 1000);
//$(this).effect("shake", { times: 2 }, 200);
});
});
“搖”的效果可以工作,但傳輸不起作用那么,如何解決這個問題呢?
試試這種格式:
<script>
$( "div" ).click(function() {
var i = 1 - $( "div" ).index( this );
$( this ).effect( "transfer", { to: $( "div" ).eq( i ) }, 1000 );
});
</script>
你可能缺少像的角色有些部分var i
。
您的代碼看起來不錯。
確保您的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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.