From 83a20c61e696c8cf9fa43a124c16fe6a1a80d6e8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 11 Mar 2015 11:42:20 -0600 Subject: [PATCH] fix(collectionRepeat): fix a dom problem with margins and position:relative Closes #3277. --- js/angular/directive/collectionRepeat.js | 12 ++++++++++++ test/html/collection-repeat/basic-list.html | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/js/angular/directive/collectionRepeat.js b/js/angular/directive/collectionRepeat.js index abb5250b21c..823f9f1fca1 100644 --- a/js/angular/directive/collectionRepeat.js +++ b/js/angular/directive/collectionRepeat.js @@ -483,6 +483,18 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) { repeaterBeforeSize += current[isVertical ? 'offsetTop' : 'offsetLeft']; } while( ionic.DomUtil.contains(scrollView.__content, current = current.offsetParent) ); + var containerPrevNode = containerNode.previousElementSibling; + var beforeStyle = containerPrevNode ? $window.getComputedStyle(containerPrevNode) : {}; + var beforeMargin = parseInt(beforeStyle[isVertical ? 'marginBottom' : 'marginRight'] || 0); + + // Because we position the collection container with position: relative, it doesn't take + // into account where to position itself relative to the previous element's marginBottom. + // To compensate, we translate the container up by the previous element's margin. + containerNode.style[ionic.CSS.TRANSFORM] = TRANSLATE_TEMPLATE_STR + .replace(PRIMARY, -beforeMargin) + .replace(SECONDARY, 0); + repeaterBeforeSize -= beforeMargin; + if (!scrollView.__clientHeight || !scrollView.__clientWidth) { scrollView.__clientWidth = scrollView.__container.clientWidth; scrollView.__clientHeight = scrollView.__container.clientHeight; diff --git a/test/html/collection-repeat/basic-list.html b/test/html/collection-repeat/basic-list.html index f808022d265..f402baf01b7 100644 --- a/test/html/collection-repeat/basic-list.html +++ b/test/html/collection-repeat/basic-list.html @@ -17,7 +17,7 @@

Basic List: Static Dimensions

-

WHATS UP

+

I have 80px margin

Button