From 09bb82c73c5650812e36dfd27d605d64d3ed32b8 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Wed, 19 Feb 2014 11:34:51 -0500 Subject: [PATCH] Fix issue with line height calculation when using older versions of jQuery --- jquery.mousewheel.js | 6 +++++- test/index.html | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index 0f86946c4f..2b852cfc68 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -58,7 +58,11 @@ }, getLineHeight: function(elem) { - return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10); + var $parent = $(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent'](); + if (!$parent.length) { + $parent = $('body'); + } + return parseInt($parent.css('fontSize'), 10); }, getPageHeight: function(elem) { diff --git a/test/index.html b/test/index.html index f04c80ce26..0c683cf4ec 100644 --- a/test/index.html +++ b/test/index.html @@ -113,7 +113,7 @@ $('#jqueryVersion').html($.fn.jquery); var loghandle = function(event, delta) { - var o = '', id = event.currentTarget.id; + var o = '', id = event.currentTarget.id || event.currentTarget.nodeName; o = '#' + id + ':'; @@ -137,6 +137,11 @@ log( o ); }; + $(document) + .mousewheel(function(event, delta) { + loghandle(event, delta); + }); + $('#test1') .mousewheel(function(event, delta) { loghandle(event, delta);