From 3b64cb8375165d0fea134efbdade1bfcd7ae95f5 Mon Sep 17 00:00:00 2001 From: Yannick Albert Date: Tue, 2 Jul 2013 11:27:58 +0200 Subject: [PATCH 1/4] Update index.html --- index.html | 55 ++++++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/index.html b/index.html index 0d812f8..93fb619 100644 --- a/index.html +++ b/index.html @@ -1,21 +1,21 @@ - - + + - jquery.fixer.js | Fix elements like any other sticky plugins it do. + jquery.fixer.js | Fix elements as `position:sticky` do. @@ -75,16 +66,14 @@
- + - + - \ No newline at end of file + From cb76f4b1a8c143b4b88cc109cf1d98be0cf97e81 Mon Sep 17 00:00:00 2001 From: Yannick Albert Date: Tue, 2 Jul 2013 11:28:21 +0200 Subject: [PATCH 2/4] Update jquery.fixer.js --- jquery.fixer.js | 93 +++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/jquery.fixer.js b/jquery.fixer.js index 9835c66..ba75567 100644 --- a/jquery.fixer.js +++ b/jquery.fixer.js @@ -1,64 +1,65 @@ /*! - * jquery.fixer.js 0.0.1 - https://github.com/yckart/jquery.fixer.js - * Fix elements like any other sticky plugins it do. + * jquery.fixer.js 0.0.3 - https://github.com/yckart/jquery.fixer.js + * Fix elements as `position:sticky` do. * * - * Copyright (c) 2012 Yannick Albert (http://yckart.com) + * Copyright (c) 2013 Yannick Albert (http://yckart.com/) | @yckart * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php). - * 2013/02/18 + * 2013/07/02 **/ + ;(function($, window) { - 'use strict'; + + var $win = $(window); + var defaults = { + gap: 0, + horizontal: false, + isFixed: $.noop + }; + + var supportSticky = function(elem) { + var prefixes = ['', '-webkit-', '-moz-', '-ms-', '-o-'], prefix; + while (prefix = prefixes.pop()) { + elem.style.cssText = 'position:' + prefix + 'sticky'; + if (elem.style.position !== '') return true; + } + return false; + }; $.fn.fixer = function(options) { - options = $.extend({}, $.fn.fixer.options, options); + options = $.extend({}, defaults, options); + var hori = options.horizontal, + cssPos = hori ? 'left' : 'top'; return this.each(function() { - var $this = $(this), - $wrap = $this.parent(), - $win = $(window); + var style = this.style, + $this = $(this), + $parent = $this.parent(); + + if (supportSticky(this)) { + style[cssPos] = options.gap + 'px'; + return; + } - $win.bind("scroll load", function() { - var cssPos = (options.horizontal ? 'left' : 'top'), - wrapPos = $wrap.offset()[options.horizontal ? 'left' : 'top'], - elemSize = $this[options.horizontal ? 'outerWidth' : 'outerHeight'](), - wrapSize = $wrap[options.horizontal ? 'outerWidth' : 'outerHeight'](), - scrollPos = $win[options.horizontal ? 'scrollLeft' : 'scrollTop'](); + $win.on('scroll', function() { + var scrollPos = $win[hori ? 'scrollLeft' : 'scrollTop'](), + elemSize = $this[hori ? 'outerWidth' : 'outerHeight'](), + parentPos = $parent.offset()[cssPos], + parentSize = $parent[hori ? 'outerWidth' : 'outerHeight'](); - if (scrollPos >= wrapPos - options.gap && (wrapSize + wrapPos - options.gap) >= (scrollPos + elemSize)) { - $this.css({ - position: 'fixed' - }).css(options.horizontal ? { - left: options.gap - } : { - top: options.gap - }); + if (scrollPos >= parentPos - options.gap && (parentSize + parentPos - options.gap) >= (scrollPos + elemSize)) { + style.position = 'fixed'; + style[cssPos] = options.gap + 'px'; options.isFixed(); - } else if (scrollPos < wrapPos) { - $this.css({ - position: 'absolute' - }).css(options.horizontal ? { - left: 0 - } : { - top: 0 - }); + } else if (scrollPos < parentPos) { + style.position = 'absolute'; + style[cssPos] = 0; } else { - $this.css({ - position: 'absolute' - }).css(options.horizontal ? { - left: wrapSize - elemSize - } : { - top: wrapSize - elemSize - }); + style.position = 'absolute'; + style[cssPos] = parentSize - elemSize + 'px'; } - }); + }).resize(); }); }; - $.fn.fixer.options = { - gap: 0, - horizontal: false, - isFixed: $.noop - }; - -})(jQuery, window); \ No newline at end of file +}(jQuery, this)); From 9814239076d2aa0b75c761a5d5efca178111dd41 Mon Sep 17 00:00:00 2001 From: Yannick Albert Date: Tue, 2 Jul 2013 11:28:46 +0200 Subject: [PATCH 3/4] Update fixer.jquery.json --- fixer.jquery.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fixer.jquery.json b/fixer.jquery.json index 777180d..69f9ed1 100644 --- a/fixer.jquery.json +++ b/fixer.jquery.json @@ -11,7 +11,7 @@ "position", "scroll" ], - "version": "0.0.1", + "version": "0.0.2", "author": { "name": "Yannick Albert", "email": "mail@yckart.com", @@ -28,4 +28,4 @@ "dependencies": { "jquery": ">=1.4" } -} \ No newline at end of file +} From 5d3c8ab214840183ba8aa8ffeca49fa89d6be1a6 Mon Sep 17 00:00:00 2001 From: Yannick Albert Date: Tue, 2 Jul 2013 11:29:31 +0200 Subject: [PATCH 4/4] Update fixer.jquery.json --- fixer.jquery.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fixer.jquery.json b/fixer.jquery.json index 69f9ed1..906cceb 100644 --- a/fixer.jquery.json +++ b/fixer.jquery.json @@ -1,7 +1,7 @@ { "name": "fixer", - "title": "jQuery Base64", - "description": "Makes Base64 en & -decoding simpler as it is.", + "title": "jQuery Fixer", + "description": "Fix elements as `position:sticky` do.", "keywords": [ "fix", "fixed", @@ -11,7 +11,7 @@ "position", "scroll" ], - "version": "0.0.2", + "version": "0.0.3", "author": { "name": "Yannick Albert", "email": "mail@yckart.com",