简单的写了个滚动的插件,准备明天用。记号,再修改。。。
View Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> *{ margin:o; padding:0; list-style:none} #relative{ position:relative; border:1px solid #F00; width:800px;height:200px; overflow:hidden} #container ul{ position:absolute; left:0;top:0} #container li{ float:left; width:100px; background:#066; margin:0 0 0 20px} </style> <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script> <script type="text/javascript" > (function($){ $.fn.scrollSwith=function(opt){ var defualts = { moveWidth:$(this).find('#relative').innerWidth() }; var opts = $.extend({}, defualts, opt); var $obj=$(this); var $ul=$obj.find('ul'); $ul.width($obj.find('li').size()*$obj.find('li').outerWidth(true)); $obj.find('#next').click(function(){ if(-$ul.position().left+$obj.find('#relative').innerWidth()<$ul.width()){ $ul.animate({left:'-='+defualts.moveWidth}); } }) $obj.find('#prev').click(function(){ console.log($ul.position().left) if($ul.position().left<0){ $ul.animate({left:'+='+defualts.moveWidth}); } }) } })(jQuery) </script> </head> <body> <div id="container"> <div id="relative"> <ul> <li>111</li> <li>222</li> <li>333</li> <li>444</li> <li>111</li> <li>222</li> <li>333</li> <li>444</li> <li>111</li> <li>222</li> <li>333</li> <li>444</li> <li>111</li> <li>222</li> <li>333</li> <li>444</li> </ul> </div> <a href="#" id="prev">prev</a> <a href="#" id="next">next</a> </div> <script type="text/javascript"> $(document).ready(function() { $('#container').scrollSwith() }); </script> </body> </html>