jQuery的绑定解除绑定动画 [英] jQuery bind unbind animation

查看:318
本文介绍了jQuery的绑定解除绑定动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了这件作品code的,我试图动画文/ DIV回块和前瞻性,
但为什么这个工程仅在第一次为placeRight功能?
是不是有什么毛病右:+ = 750属性

  $(文件)。就绪(函数(){
   $(#文本),单击(placeRight)。
});    VAR placeRight =功能(){
      $(#文本),动画({右:+ = 750},1300);
      $(#文)解除绑定(点击)。
      $(#文本),单击(placeLeft)。
    }    VAR placeLeft =功能(){
      $(#文本),动画({左:+ = 750},1300);
      $(#文)解除绑定(点击)。
      $(#文本),单击(placeRight)。
    }


解决方案

是啊,你有双倍时间 $(#文本),动画({左:+ = 750},1300 ); 结果
所以你想始终将其放置到+ 750px位置

改变它像这样

  $(文件)。就绪(函数(){
   $(#文本),单击(placeRight)。
});VAR placeRight =功能(){
  $(#文本),动画({右:+ = 750},1300);
  $(#文)解除绑定(点击)。
  $(#文本),单击(placeLeft)。
}VAR placeLeft =功能(){
  $(#文本),动画({左: - = 750},1300); //或{右:0}
  $(#文)解除绑定(点击)。
  $(#文本),单击(placeRight)。
}

I made this piece of code,i'm trying to animate a block of text/div back and forward, but why this works only the first time for the "placeRight" function? Is there something wrong with the right : "+=750" attribute?

$(document).ready( function ( ) {
   $("#text").click(placeRight);
});   

    var placeRight = function() {     
      $("#text").animate( { right :  "+=750" }, 1300); 
      $("#text").unbind("click"); 
      $("#text").click(placeLeft);
    }

    var placeLeft = function() {     
      $("#text").animate( { left :  "+=750" }, 1300); 
      $("#text").unbind("click");
      $("#text").click(placeRight);
    }

解决方案

Yeah, you have double time $("#text").animate( { left : "+=750" }, 1300);
so you're trying to place it always to +750px position

change it like this

$(document).ready( function ( ) {
   $("#text").click(placeRight);
});   

var placeRight = function() {     
  $("#text").animate( { right :  "+=750" }, 1300);
  $("#text").unbind("click"); 
  $("#text").click(placeLeft);
}

var placeLeft = function() {     
  $("#text").animate( { left :  "-=750" }, 1300); //or { right: 0 }
  $("#text").unbind("click");
  $("#text").click(placeRight);
}

这篇关于jQuery的绑定解除绑定动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆