diff --git a/dist/smoothscroll.js b/dist/smoothscroll.js
index 916cd11..926f8bf 100644
--- a/dist/smoothscroll.js
+++ b/dist/smoothscroll.js
@@ -252,14 +252,15 @@
}
// LET THE SMOOTHNESS BEGIN!
- var scrollableParent = findScrollableParent(this);
+ var el = this;
+ var scrollableParent = findScrollableParent(el);
var parentRects = scrollableParent.getBoundingClientRect();
- var clientRects = this.getBoundingClientRect();
+ var clientRects = el.getBoundingClientRect();
- if (scrollableParent !== d.body) {
+ while (scrollableParent !== d.body) {
// reveal element inside parent
smoothScroll.call(
- this,
+ el,
scrollableParent,
scrollableParent.scrollLeft + clientRects.left - parentRects.left,
scrollableParent.scrollTop + clientRects.top - parentRects.top
@@ -270,13 +271,21 @@
top: parentRects.top,
behavior: 'smooth'
});
- } else {
- // reveal element in viewport
- w.scrollBy({
- left: clientRects.left,
- top: clientRects.top,
- behavior: 'smooth'
- });
+
+ el = scrollableParent;
+ scrollableParent = findScrollableParent(el);
+ parentRects = scrollableParent.getBoundingClientRect();
+ clientRects = el.getBoundingClientRect();
+
+ }
+ // reveal element in viewport
+ w.scrollBy({
+ left: clientRects.left,
+ top: clientRects.top,
+ behavior: 'smooth'
+ });
+ };
+ }
}
};
}
diff --git a/index.html b/index.html
index 7db027b..a7bb01d 100644
--- a/index.html
+++ b/index.html
@@ -224,7 +224,35 @@
element.scrollIntoView
adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
- hello!
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ hello!
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
+ adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
adipisci consequuntur maiores, quo in nulla ratione facere distinctio beatae, quae consequatur ab labore dolorum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui iure obcaecati, repudiandae aspernatur cumque recusandae
diff --git a/src/smoothscroll.js b/src/smoothscroll.js
index e13a320..4e64f0e 100644
--- a/src/smoothscroll.js
+++ b/src/smoothscroll.js
@@ -246,14 +246,15 @@
}
// LET THE SMOOTHNESS BEGIN!
- var scrollableParent = findScrollableParent(this);
+ var el = this;
+ var scrollableParent = findScrollableParent(el);
var parentRects = scrollableParent.getBoundingClientRect();
- var clientRects = this.getBoundingClientRect();
+ var clientRects = el.getBoundingClientRect();
- if (scrollableParent !== d.body) {
+ while (scrollableParent !== d.body) {
// reveal element inside parent
smoothScroll.call(
- this,
+ el,
scrollableParent,
scrollableParent.scrollLeft + clientRects.left - parentRects.left,
scrollableParent.scrollTop + clientRects.top - parentRects.top
@@ -264,14 +265,19 @@
top: parentRects.top,
behavior: 'smooth'
});
- } else {
- // reveal element in viewport
- w.scrollBy({
- left: clientRects.left,
- top: clientRects.top,
- behavior: 'smooth'
- });
+
+ el = scrollableParent;
+ scrollableParent = findScrollableParent(el);
+ parentRects = scrollableParent.getBoundingClientRect();
+ clientRects = el.getBoundingClientRect();
+
}
+ // reveal element in viewport
+ w.scrollBy({
+ left: clientRects.left,
+ top: clientRects.top,
+ behavior: 'smooth'
+ });
};
}