absoulteInTop.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * jquery.scrollFollow.js
  3. * Copyright (c) 2008 Net Perspective (http://kitchen.net-perspective.com/)
  4. * Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
  5. *
  6. * @author R.A. Ray
  7. *
  8. * @projectDescription jQuery plugin for allowing an element to animate down as the user scrolls the page.
  9. *
  10. * @version 0.4.0
  11. *
  12. * @requires jquery.js (tested with 1.2.6)
  13. * @requires ui.core.js (tested with 1.5.2)
  14. *
  15. * @optional jquery.cookie.js (http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/)
  16. * @optional jquery.easing.js (http://gsgd.co.uk/sandbox/jquery/easing/ - tested with 1.3)
  17. *
  18. * @param speed int - Duration of animation (in milliseconds)
  19. * default: 500
  20. * @param offset int - Number of pixels box should remain from top of viewport
  21. * default: 0
  22. * @param easing string - Any one of the easing options from the easing plugin - Requires jQuery Easing Plugin < http://gsgd.co.uk/sandbox/jquery/easing/ >
  23. * default: 'linear'
  24. * @param container string - ID of the containing div
  25. * default: box's immediate parent
  26. * @param killSwitch string - ID of the On/Off toggle element
  27. * default: 'killSwitch'
  28. * @param onText string - killSwitch text to be displayed if sliding is enabled
  29. * default: 'Turn Slide Off'
  30. * @param offText string - killSwitch text to be displayed if sliding is disabled
  31. * default: 'Turn Slide On'
  32. * @param relativeTo string - Scroll animation can be relative to either the 'top' or 'bottom' of the viewport
  33. * default: 'top'
  34. * @param delay int - Time between the end of the scroll and the beginning of the animation in milliseconds
  35. * default: 0
  36. */
  37. ( function( $ ) {
  38. $.absoulteTop = function ( box, options ){
  39. var scrollTop=$(box).attr('usesclflw');
  40. if(scrollTop && ('false'==scrollTop)) return;
  41. var ie6 = ($.browser.msie && ($.browser.version == 6.0) && !$.support.style)?true:false,
  42. initTop = 0,obj=$(box).closest("[handScroll]");
  43. if(obj.length==0)
  44. obj=$(window);
  45. obj.scroll(function () {
  46. scrollTop = obj.scrollTop();
  47. //向下滚动
  48. if (scrollTop < initTop && scrollTop == 0) {
  49. if (ie6)
  50. $(box).css({"position": "relative", "top": "0","margin-top":"10px" });
  51. else
  52. $(box).css({"position": "relative", "top": "0"});
  53. } else {
  54. if (ie6)
  55. $(box).css({"position": "absolute", "top":options.top+"px", "margin-top":"0","z-index":options.zIndex });
  56. else
  57. $(box).css({"position": "fixed", "top": options.top+"px","width":"100%","z-index":options.zIndex});
  58. }
  59. setTimeout(function(){initTop = scrollTop;},0);
  60. });
  61. };
  62. $.fn.absoulteInTop = function ( options ){
  63. options = options || {};
  64. options.top=options.top|| -5;
  65. options.zIndex =options.zIndex || 100;
  66. this.each(function() {
  67. new $.absoulteTop( this, options );
  68. });
  69. return this;
  70. };
  71. })( jQuery );
  72. $(function(){
  73. $.extend({
  74. initAbsoulteInTop:function(){
  75. try{
  76. $('.panel-top').absoulteInTop();
  77. }catch(e){}
  78. }});
  79. // $.initAbsoulteInTop();
  80. });