mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Use offset
to calculate eyeline, which is safer than position
This commit is contained in:
parent
e527294904
commit
1fb409e521
@ -4,13 +4,13 @@ import { cloak, uncloak } from 'discourse/widgets/post-stream';
|
|||||||
import { isWorkaroundActive } from 'discourse/lib/safari-hacks';
|
import { isWorkaroundActive } from 'discourse/lib/safari-hacks';
|
||||||
import offsetCalculator from 'discourse/lib/offset-calculator';
|
import offsetCalculator from 'discourse/lib/offset-calculator';
|
||||||
|
|
||||||
function findTopView($posts, viewportTop, min, max) {
|
function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
|
||||||
if (max < min) { return min; }
|
if (max < min) { return min; }
|
||||||
|
|
||||||
while (max > min) {
|
while (max > min) {
|
||||||
const mid = Math.floor((min + max) / 2);
|
const mid = Math.floor((min + max) / 2);
|
||||||
const $post = $($posts[mid]);
|
const $post = $($posts[mid]);
|
||||||
const viewBottom = $post.position().top + $post.height();
|
const viewBottom = ($post.offset().top - postsWrapperTop) + $post.height();
|
||||||
|
|
||||||
if (viewBottom > viewportTop) {
|
if (viewBottom > viewportTop) {
|
||||||
max = mid-1;
|
max = mid-1;
|
||||||
@ -71,9 +71,10 @@ export default MountWidget.extend({
|
|||||||
|
|
||||||
const windowTop = $w.scrollTop();
|
const windowTop = $w.scrollTop();
|
||||||
|
|
||||||
|
const postsWrapperTop = $('.posts-wrapper').offset().top;
|
||||||
const $posts = this.$('.onscreen-post, .cloaked-post');
|
const $posts = this.$('.onscreen-post, .cloaked-post');
|
||||||
const viewportTop = windowTop - slack;
|
const viewportTop = windowTop - slack;
|
||||||
const topView = findTopView($posts, viewportTop, 0, $posts.length-1);
|
const topView = findTopView($posts, viewportTop, postsWrapperTop, 0, $posts.length-1);
|
||||||
|
|
||||||
let windowBottom = windowTop + windowHeight;
|
let windowBottom = windowTop + windowHeight;
|
||||||
let viewportBottom = windowBottom + slack;
|
let viewportBottom = windowBottom + slack;
|
||||||
|
Loading…
Reference in New Issue
Block a user