首页 > 代码库 > jQuery滑动并响应事件

jQuery滑动并响应事件

jQuery滑动并打开指定页面:

<!DOCTYPE html><html><head><script src="http://code.jquery.com/jquery-1.11.1.min.js"></script><script> $(document).ready(function(){  $(".a").click(function(){    $(".a").animate({left:250px},function(){location.href="http://www.baidu.com"});  });});</script> </head> <body><p>默认情况下,所有 HTML 元素的位置都是静态的,并且无法移动。如需对位置进行操作,记得首先把元素的 CSS position 属性设置为 relative、fixed 或 absolute。</p><h3>点击方块执行</h3><div class=‘a‘ style="background:#98bf21;height:100px;width:100px;position:absolute;"></div></body></html>
View Code

jQuery来回滑动并响应事件:

<!DOCTYPE html><html><head><script src="jquery/jquery.js"></script><script> $(document).ready(function(){  $("#box").toggle(function(){    $("#box").animate({left:200px},function(){alert(Slide to the right);}).text(ON);},    function(){    $("#box").animate({left:‘‘},function(){alert(Sliding to the left);}).text(OFF);}  );});</script> </head><body><p>默认情况下,所有 HTML 元素的位置都是静态的,并且无法移动。如需对位置进行操作,记得首先把元素的 CSS position 属性设置为 relative、fixed 或 absolute。</p><h3>点击方块执行</h3><div id=‘box‘ style="background:#98bf21;height:100px;width:100px;position:absolute;">OFF</div></body></html>
View Code

 jQuery下载:http://files.cnblogs.com/liuswi/jquery.js