From f16c26470e015b533283194973cc4bec470c0c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E4=BA=9A=E8=BE=89?= <634236658@qq.com> Date: Fri, 7 Nov 2014 16:44:51 +0800 Subject: [PATCH] add option:scrollElement --- src/jquery.scrollUp.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/jquery.scrollUp.js b/src/jquery.scrollUp.js index 445df9b..65139d0 100644 --- a/src/jquery.scrollUp.js +++ b/src/jquery.scrollUp.js @@ -34,7 +34,7 @@ $self.attr('title', o.scrollTitle); } - $self.appendTo('body'); + $self.appendTo(document.body); // If not using an image display text if (!(o.scrollImg || o.scrollTrigger)) { @@ -89,8 +89,8 @@ } // Scroll function - scrollEvent = $(window).scroll(function () { - if ($(window).scrollTop() > scrollDis) { + scrollEvent = $(o.scrollElement).scroll(function () { + if ($(o.scrollElement).scrollTop() > scrollDis) { if (!triggerVisible) { $self[animIn](animSpeed); triggerVisible = true; @@ -117,7 +117,12 @@ $self.click(function (e) { e.preventDefault(); - $('html, body').animate({ + var ele = o.scrollElement; + if (ele === window) + ele = 'html, body'; + + + $(ele).animate({ scrollTop: scrollTarget }, o.scrollSpeed, o.easingType); }); @@ -138,7 +143,8 @@ scrollTitle: false, // Set a custom title if required. Defaults to scrollText scrollImg: false, // Set true to use image activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF' - zIndex: 2147483647 // Z-Index for the overlay + zIndex: 2147483647, // Z-Index for the overlay + scrollElement: window }; // Destroy scrollUp plugin and clean all modifications to the DOM @@ -149,11 +155,11 @@ // If 1.7 or above use the new .off() if ($.fn.jquery.split('.')[1] >= 7) { - $(window).off('scroll', scrollEvent); + $($.fn.scrollUp.settings.scrollElement).off('scroll', scrollEvent); - // Else use the old .unbind() + // Else use the old .unbind() } else { - $(window).unbind('scroll', scrollEvent); + $($.fn.scrollUp.settings.scrollElement).unbind('scroll', scrollEvent); } };