jquery数据缓存

juery可以动态地在一个元素上加上键值对,其中“对”甚至可以是对象
  $('#data').data('test',{name:'yuchao',age:24});
        alert($('#data').data('test').age);       
        $('#data').removeData('test');
        alert($('#data').data('test'));
<div id="data"></div>


queue(name,callback)

在匹配的元素的队列最后添加一个函数

Adds a new function, to be executed, onto the end of the queue of all matched elements.

返回值

jQuery

参数

name (String) :队列名,默认为fx

callback (Function) : 要添加进队列的函数

示例

插入一个自定义函数 如果函数执行后要继续队列,则执行 jQuery(this).dequeue();

HTML 代码:

  <style>
  div { margin:3px; width:40px; height:40px;
        position:absolute; left:0px; top:30px; 
        background:green; display:none; }
  div.newcolor { background:blue; }
  </style>
  Click here...
  <div></div>

jQuery 代码:

$(document.body).click(function () {
      $("div").show("slow");
      $("div").animate({left:'+=200'},2000);
      $("div").queue(function () {
          $(this).addClass("newcolor");
          $(this).dequeue();
      });
      $("div").animate({left:'-=200'},500);
      $("div").queue(function () {
          $(this).removeClass("newcolor");
          $(this).dequeue();
      });
      $("div").slideUp();
});



queue(name,queue)

将匹配元素的队列用新的一个队列来代替(函数数组).

dequeue([name])

从队列最前端移除一个队列函数,并执行他。

Removes a queued function from the front of the queue and executes it.

返回值

jQuery

参数

name (String) :队列名,默认为fx

示例

用dequeue来结束自定义队列函数,并让队列继续进行下去。

HTML 代码:

  <style>
  div { margin:3px; width:50px; position:absolute;
        height:50px; left:10px; top:30px; 
        background-color:yellow; }
  div.red { background-color:red; }
  </style>

  <button>Start</button>
  <div></div>

jQuery 代码:

  $("button").click(function () {
      $("div").animate({left:'+=200px'}, 2000);
      $("div").animate({top:'0px'}, 600);
      $("div").queue(function () {
          $(this).toggleClass("red");
          $(this).dequeue();
      });
      $("div").animate({left:'10px', top:'30px'}, 700);
  });





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值