jquery.fixed.1.3.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* =================================================
  2. //
  3. // jQuery Fixed Plugins 1.3.1
  4. // Url: www.sucaijiayuan.com
  5. // Data : 2012-03-30
  6. //
  7. // 参数 : float --> 悬浮方向[left or right]
  8. // minStatue --> 最小状态,只有show_btn
  9. // skin --> 皮肤控制
  10. // durationTime --> 完成时间
  11. //事例 :
  12. $("#scrollsidebar2").fix({
  13. float : 'right', //default.left or right
  14. minStatue : true, //default.false or true
  15. skin : 'green', //default.gray or yellow 、blue 、green 、orange 、white
  16. durationTime : 1000 //
  17. });
  18. //
  19. // =================================================*/
  20. ;(function($){
  21. $.fn.fix = function(options){
  22. var defaults = {
  23. float : 'left',
  24. minStatue : false,
  25. skin : 'gray',
  26. durationTime : 1000
  27. }
  28. var options = $.extend(defaults, options);
  29. this.each(function(){
  30. //获取对象
  31. var thisBox = $(this),
  32. closeBtn = thisBox.find('.close_btn' ),
  33. show_btn = thisBox.find('.show_btn' ),
  34. sideContent = thisBox.find('.side_content'),
  35. sideList = thisBox.find('.side_list')
  36. ;
  37. var defaultTop = thisBox.offset().top; //对象的默认top
  38. thisBox.css(options.float, 0);
  39. if(options.minStatue){
  40. $(".show_btn").css("float", options.float);
  41. sideContent.css('width', 0);
  42. show_btn.css('width', 25);
  43. }
  44. //皮肤控制
  45. if(options.skin) thisBox.addClass('side_'+options.skin);
  46. //核心scroll事件
  47. $(window).bind("scroll",function(){
  48. var offsetTop = defaultTop + $(window).scrollTop() + "px";
  49. thisBox.animate({
  50. top: offsetTop
  51. },
  52. {
  53. duration: options.durationTime,
  54. queue: false //此动画将不进入动画队列
  55. });
  56. });
  57. //close事件
  58. closeBtn.bind("click",function(){
  59. sideContent.animate({width: '0px'},"fast");
  60. show_btn.stop(true, true).delay(300).animate({ width: '25px'},"fast");
  61. });
  62. //show事件
  63. show_btn.click(function() {
  64. $(this).animate({width: '0px'},"fast");
  65. sideContent.stop(true, true).delay(200).animate({ width: '154px'},"fast");
  66. });
  67. }); //end this.each
  68. };
  69. })(jQuery);
  70. /*
  71. 本代码由素材家园收集并编辑整理;
  72. 尊重他人劳动成果;
  73. 转载请保留素材家园链接 - www.sucaijiayuan.com
  74. */