Skip to content

Instantly share code, notes, and snippets.

@KostyaTretyak

KostyaTretyak/sync.js

Last active Aug 29, 2015
Embed
What would you like to do?
Скрипт створено за допомогою jQuery для синхронної прокрутки двох div'ів
$(document).ready(function(){
var master = "master"; // this is id div
var slave = "slave"; // this is other id div
var master_tmp, slave_tmp, timer;
var sync = function ()
{
if($(this).attr("id") == slave)
{
master_tmp = master;
slave_tmp = slave;
master = slave;
slave = master_tmp;
}
$("#" + slave).unbind("scroll");
var percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight);
var x = percentage * ($("#" + slave).get(0).scrollHeight - $("#" + slave).get(0).offsetHeight);
$("#" + slave).scrollTop(x);
if(typeof(timer) !== "undefind")
clearTimeout(timer);
timer = setTimeout(function(){ $("#" + slave).scroll(sync) }, 300)
}
$("#" + master + ", #" + slave).scroll(sync);
});
@KostyaTretyak

This comment has been minimized.

Copy link
Owner Author

@KostyaTretyak KostyaTretyak commented Jan 13, 2015

Можна проглянути DEMO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.