Skip to content

Commit

Permalink
More fix the Firefox scrolling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Oct 12, 2022
1 parent 784301a commit da483d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion sparqlGraphWeb/sparqlGraph/js/plotlyplotter.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ define([ // properly require.config'ed bootstrap-modal

//Plotly.newPlot( plotDiv, [ { x: [0,1,2,3,1,1,6],type: 'histogram',}]);
div.appendChild(plotDiv);

if (optCallback)
optCallback();
setTimeout(optCallback, 10); // hope to draw first
},

adjustLayoutDimensions : function(layout, div) {
Expand Down
26 changes: 24 additions & 2 deletions sparqlGraphWeb/sparqlGraph/js/sparqlgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -2444,11 +2444,33 @@
var myScrollIntoViewIfNeeded = function (el) {
var r = el.getBoundingClientRect();

if (r.top <= 0 || r.top > window.innerHeight) {
el.scrollIntoView();
if (r.top > window.pageYOffset + window.innerHeight * .9) {
// scroll down until top of element is mid-window
smoothScrollTo(r.top - window.innerHeight / 2);
} else if (r.top < window.pageYOffset ) {
// scroll up until top of element shows
smoothScrollTo(r.top);
}
};

var smoothScrollTo = function(posY) {
var CHUNK = Math.max(10, window.innerHeight / 25);
var TIME_INTERVAL = 50;
var diff = window.pageYOffset - posY;
diff = Math.max(-CHUNK, -diff);
diff = Math.min(CHUNK, diff);

console.log("posY: " + posY + " scrollY: " + window.pageYOffset + " diff: " + diff);
var oldScrollY = window.pageYOffset;
window.scrollBy(0, diff);

// if scrolling had an effect and there is at least CHUNK more to go...
if (window.scrollY != oldScrollY && (diff == CHUNK || diff == -CHUNK)) {
setTimeout(smoothScrollTo.bind(this, posY), TIME_INTERVAL);
}

}

//
// add data to network one CHUNK_SIZE at a time
// use setTimeout to keep UI updates smooth
Expand Down

0 comments on commit da483d2

Please sign in to comment.