8
I have two div
same height, but with different content. And when I do scroll in one, I wanted the other to follow in the same (or at least close to the same) position.
The problem is that their contents are not the same size, and consequently the size of the scroll bar ends up being different between them. But even with the size difference I would like to make the scroll of the second accompany that of the first, so that if I rolled until the end of the first div
the second should also go to the end, even if it is of larger content.
I don’t know if I could be clear, but here follows an example of what I intend to do.
(function () {
var target = $("#target")[0]; // <== Getting raw element
$("#source").scroll(function () {
target.scrollTop = this.scrollTop;
target.scrollLeft = this.scrollLeft;
});
})();
I used a solution found in this answer, but the problem is precisely that the scroll the second only goes as far as the first one ends, that is, it does not behave properly.
Is there any way to create a "smart scroll-mirror"?
You want the scroll to be done proportionately, right?
– Guilherme Oderdenge
@Exact Guilhermeoderdenge, I found a site that has an example very close to what I want: http://dillinger.io - I’m taking a look at his code, but any answer with a solution is still much welcome
– Kazzkiq
See if it helps you: http://scripterlative.com/files/synchdivscroll.htm
– Guilherme Oderdenge
Reminded me of the Stackedit.io.
– brasofilo
@brasofilo this site that you passed is exactly what I wanted, I’ll snoop on his repository, thanks!
– Kazzkiq