Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit 34ef539

Browse files
committed
Fix scroll jumping on webkit
1 parent 41d4bed commit 34ef539

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lib/view/chat/page.html

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@
381381
</div>
382382

383383
<script type="text/javascript" charset="utf-8">
384+
// Which element is on top.
385+
var topElement = null
386+
// Scroll to the unread marker, or bottom if not found.
387+
function scrollToUnreadMarker() {
388+
var marker = document.getElementById('unread-marker')
389+
if (marker) {
390+
var rect = marker.getBoundingClientRect()
391+
window.scrollTo(0, rect.top + window.pageYOffset - (window.innerHeight / 2))
392+
} else {
393+
window.scrollTo(0, document.body.scrollHeight)
394+
}
395+
}
396+
// For IE we need to scroll after ready, as the window body's size may be
397+
// incorrect before showing the browser.
398+
// For morden browsers scrolling before showing has the best visual effect.
399+
var isIE = /Trident|MSIE/.test(navigator.userAgent)
400+
if (!isIE)
401+
scrollToUnreadMarker()
384402
// Helper to pass callbacks to UI.
385403
var callbacks = {}
386404
var nextCallbackId = 0
@@ -414,8 +432,6 @@
414432
wrapper.innerHTML = html
415433
return wrapper.childNodes
416434
}
417-
// Which element is on top.
418-
var topElement = null
419435
// External API to add a new message.
420436
var messages = document.getElementById('messages')
421437
window.addMessage = function(html, firstUnread, fromCurrentUser) {
@@ -526,16 +542,9 @@
526542
window.onresize = scrollToPreivousTopElement
527543
// We are ready.
528544
wey.ready()
529-
// Scroll to the unread marker, or bottom if not found.
530-
// Note: this must be done after ready, as the window body's size may be
531-
// incorrect before showing the browser.
532-
var marker = document.getElementById('unread-marker')
533-
if (marker) {
534-
var rect = marker.getBoundingClientRect()
535-
window.scrollTo(0, rect.top + window.pageYOffset - (window.innerHeight / 2))
536-
} else {
537-
window.scrollTo(0, document.body.scrollHeight)
538-
}
545+
// See comment above on IE.
546+
if (isIE)
547+
scrollToUnreadMarker()
539548
</script>
540549
</body>
541550
</html>

0 commit comments

Comments
 (0)