开发者

jQuery noob: transfer not transferring

开发者 https://www.devze.com 2023-01-03 17:57 出处:网络
I made an example, I copied it straight from the jQuery website yet, it doesn\'t transfer.. HTML: <div class=\"addToCart\">

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/

  1. You weren't including the UI library in the example
  2. $(".handelv").eq(i) where i = 1. Your selector only matches one element; so you need to set i to 0.
  3. 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);
});

  });​
0

精彩评论

暂无评论...
验证码 换一张
取 消