Skip to content

Commit

Permalink
Account for subject borders (#166) fixes #165
Browse files Browse the repository at this point in the history
Uses offsetWidth / offsetHeight to calculate the size of the principal box of the subject which includes borders.
  • Loading branch information
johannesodland authored Oct 20, 2023
1 parent a4b62f3 commit 00941c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions demo/view-timeline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
}

#target {
box-sizing: border-box;
background-color: rgba(0, 0, 255, 0.5);
display: inline-block;
flex: none;
Expand All @@ -63,6 +64,10 @@
height: 650px;
}

#target.borders {
border: 25px solid #e0c58b;
}

#container.rtl > #target,
#container.ltr > #target {
height: 90%;
Expand Down Expand Up @@ -133,6 +138,8 @@
<br>
<input type="checkbox" name="subject-size" id="taller-than-scrollport-subject">
<label for="taller-than-scrollport-subject">Taller than scrollport subject</label>
<input type="checkbox" name="subject-borders" id="subject-has-borders">
<label for="subject-has-borders">Subject has borders</label>
</body>
<script src="../../dist/scroll-timeline.js"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -206,6 +213,13 @@
target.classList.remove('taller');
}
break;
case 'subject-borders':
if(event.target.checked) {
target.classList.add('borders');
} else {
target.classList.remove('borders');
}
break;
}

createAnimations();
Expand Down
4 changes: 2 additions & 2 deletions src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ export function calculateRange(phase, container, target, axis, optionsInset) {
if (axis == 'x' ||
(axis == 'inline' && horizontalWritingMode) ||
(axis == 'block' && !horizontalWritingMode)) {
viewSize = target.clientWidth;
viewSize = target.offsetWidth;
viewPos = left;
if (rtl)
viewPos += container.scrollWidth - container.clientWidth;
containerSize = container.clientWidth;
} else {
// TODO: support sideways-lr
viewSize = target.clientHeight;
viewSize = target.offsetHeight;
viewPos = top;
containerSize = container.clientHeight;
}
Expand Down

0 comments on commit 00941c8

Please sign in to comment.