Created
May 10, 2011 14:59
-
-
Save jboesch/964626 to your computer and use it in GitHub Desktop.
One scrollbar to scroll them all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hide scrollbars on the calendar day instances (jQuery fullCalendar plugin: http://arshaw.com/fullcalendar/) | |
var $scrollbox = $('.cal-item .fc-view-agendaDay.fc-agenda > div > div') | |
// Hide the current scrollbars on a bunch of calendar divs (side-by-side) | |
.css('overflow-y', 'hidden') | |
// Since they're hidden and we're using another scrollbar to control | |
// them, we need to bind mousewheel to make sure that we can still | |
// mousewheel over the hidden boxes (jQuery mousewheel plugin) | |
.mousewheel(function(event, delta, deltaX, deltaY){ | |
// #scrolly is my new scrollbar to control them | |
var y = $('#scrolly').scrollTop(); | |
var strength = delta * 50; | |
var dir = (delta > 0) ? 'up' : 'down'; | |
if(dir == 'up'){ | |
strength = -(delta * 30); | |
y+=strength; | |
} | |
else { | |
strength = (delta * 30); | |
y-=strength; | |
} | |
$('#scrolly').scrollTop(y); | |
}); | |
$('#scrolly div').height($scrollbox[0].scrollHeight + 50); | |
// Now when I scroll on my newly created scrollbar, I force it to scroll the div's of the | |
// calendar instances (that I set overflow-y: hidden above) | |
$('#scrolly').scroll(function(e){ | |
e.preventDefault(); | |
$scrollbox.scrollTop($(this).scrollTop()); | |
}); | |
// CSS | |
#scrolly { | |
float: left; | |
height: 400px; | |
overflow: scroll; | |
} | |
#scrolly div { | |
/* height set via JS */ | |
width: 1px; /* firefox */ | |
} | |
// HTML | |
<div id="scrolly"> | |
<div></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment