标签:
<script src="http://apps.bdimg.com/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> jQuery.fn.anchorGoWhere = function(options){ var obj = jQuery(this); var defaults = {target:0, timer:500}; var o = jQuery.extend(defaults,options); obj.each(function(i){ jQuery(obj[i]).click(function(){ var _rel = jQuery(this).attr("href").substr(1); switch(o.target){ case 1: var _targetTop = jQuery("#"+_rel).offset().top; jQuery("html,body").animate({scrollTop:_targetTop},o.timer); break; case 2: var _targetLeft = jQuery("#"+_rel).offset().left; jQuery("html,body").animate({scrollLeft:_targetLeft},o.timer); break; } return false; }); }); }; $("#mybtn").anchorGoWhere({target:1}); //这里是点击按钮的ID </script>
标签:
原文地址:http://www.cnblogs.com/mlwArea/p/4620448.html