Only scroll into view if not already visible
This commit is contained in:
parent
da1319ca68
commit
f5b386f70d
@ -140,6 +140,15 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function isInViewport(element) {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return (
|
||||
rect.top >= 0 &&
|
||||
rect.left >= 0 &&
|
||||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
|
||||
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
||||
);
|
||||
}
|
||||
const vm = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
@ -212,7 +221,9 @@
|
||||
this.selectedItem = undefined;
|
||||
} else {
|
||||
this.selectedItem = item.ID;
|
||||
document.getElementById(this.selectedItem).scrollIntoView();
|
||||
if (!isInViewport(document.getElementById(this.selectedItem))) {
|
||||
document.getElementById(this.selectedItem).scrollIntoView();
|
||||
}
|
||||
item.PendingRead = true;
|
||||
fetch(`/api/read/${item.ID}`, {method: "POST"})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user