From 291a96905c8680b774e78f2b8999c7676afe0059 Mon Sep 17 00:00:00 2001 From: Tad Fisher Date: Mon, 1 Aug 2011 10:06:36 -1000 Subject: [PATCH] Respond to mousewheel on fixed columns --- jquery.fixedheadertable.js | 13 +++++++++++++ lib/jquery.mousewheel.min.js | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/jquery.mousewheel.min.js diff --git a/jquery.fixedheadertable.js b/jquery.fixedheadertable.js index 4edd956..ae4e81d 100644 --- a/jquery.fixedheadertable.js +++ b/jquery.fixedheadertable.js @@ -466,7 +466,20 @@ $fixedColumn.css({ 'height': 0, 'width': fixedColumnWidth + }) + + + // bind mousewheel events + var maxTop = $fixedColumn.find('.fht-tbody .fht-table').height() - $fixedColumn.find('.fht-tbody').height(); + console.log(maxTop); + $fixedColumn.find('.fht-table').bind('mousewheel', function(event, delta) { + var top = parseInt($(this).css('marginTop'), 10) + (delta > 0 ? 40 : -40); + if (top > 0) top = 0; + if (top < -maxTop) top = -maxTop; + $(this).css('marginTop', top); + $fixedBody.find('.fht-tbody').scrollTop(-top); }); + // set width of body table wrapper $fixedBody.css({ diff --git a/lib/jquery.mousewheel.min.js b/lib/jquery.mousewheel.min.js new file mode 100644 index 0000000..a17391e --- /dev/null +++ b/lib/jquery.mousewheel.min.js @@ -0,0 +1,12 @@ +/* Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net) + * Licensed under the MIT License (LICENSE.txt). + * + * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers. + * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. + * Thanks to: Seamus Leahy for adding deltaX and deltaY + * + * Version: 3.0.4 + * + * Requires: 1.2.2+ + */ +(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(i){var g=i||window.event,f=[].slice.call(arguments,1),j=0,h=true,e=0,d=0;i=c.event.fix(g);i.type="mousewheel";if(i.wheelDelta){j=i.wheelDelta/120}if(i.detail){j=-i.detail/3}d=j;if(g.axis!==undefined&&g.axis===g.HORIZONTAL_AXIS){d=0;e=-1*j}if(g.wheelDeltaY!==undefined){d=g.wheelDeltaY/120}if(g.wheelDeltaX!==undefined){e=-1*g.wheelDeltaX/120}f.unshift(i,j,e,d);return c.event.handle.apply(this,f)}})(jQuery); \ No newline at end of file