jQuery noob: transfer not transferring
I made an example, I copied it straight from the jQuery website yet, it doesn't transfer..
HTML:
<div class="addToCart">
BLAHHHH
</div>
<br>
<br&开发者_StackOverflow社区gt;
<br>
<br>
<div class="handelv">
MORE BLAAAHH
</div>
jQuery:
$(document).ready(function() {
$(".addToCart").click(function () {
var i = 1 - $(".addToCart").index(this);
$(this).effect("transfer", { to: $(".handelv").eq(i) }, 1000);
});
});
What have I gotten wrong?
http://jsfiddle.net/TuMsc/7/
- You weren't including the UI library in the example
$(".handelv").eq(i)wherei = 1. Your selector only matches one element; so you need to setito0.- You need to define a style for
.ui-effects-transfer, so that a visible-something happens.
All your code can be changed to just:
$(".addToCart").click(function () {
$(this).effect("transfer", { to: $(".handelv") }, 1000);
});
The problem you have is misunderstanding how the selectors in the example are being used. The index and eq methods are selecting either the first or second div.
if you change the code to this:
$(".addToCart").click(function () {
$(this).effect("transfer", { to: $(".handelv") }, 1000);
});
You also need to set .ui-effects-transfer to display something; a border is used in the example (which is the class of the element that is displayed during the transfer) and include jquery UI
try this:
$(document).ready(function() {
$(".addToCart").click(function () {
$(this).effect("transfer", { to: $(".handelv") }, 1000);
});
});
加载中,请稍侯......
精彩评论