Skip to content

Instantly share code, notes, and snippets.

@wojtha
Created December 14, 2012 12:43
Show Gist options
  • Select an option

  • Save wojtha/4285234 to your computer and use it in GitHub Desktop.

Select an option

Save wojtha/4285234 to your computer and use it in GitHub Desktop.
Drupal - add floating left and right banner regions
<div id="main">
<?php if (!empty($banner_left)) { print '<div id="banner-left" class="scrollable">' . render($banner_left) . '</div>'; } ?>
<?php if (!empty($banner_right)) { print '<div id="banner-right" class="scrollable">' . render($banner_right) . '</div>'; } ?>
<!-----8<-----SNIP----------------------------------------------------------------->
</div>
/* Banner scrolling */
(function($) {
$(document).ready(function () {
$('.scrollable').each( function(){
var $el = $(this);
var base_y = $el.offset().top - parseFloat($el.css('marginTop').replace(/auto/, 0));
var base_top = $el.css('top');
$(window).scroll(function (event) {
var window_y = $(document).scrollTop();
if (window_y >= base_y) {
$el.css('top', window_y - base_y + 30);
}
else {
$el.css('top', base_top);
}
});
})
});
})(jQuery);
#main {
position: relative;
}
#banner-left,#banner-right{
width: 160px;
height: 600px;
position: absolute;
top: 27px;
z-index: 99;
}
#banner-left{
left: -165px;
}
#banner-right{
right: -165px;
}
regions[banner_left] = Banner Left
regions[banner_right] = Banner Right
#-----8<-----SNIP-------------------
stylesheets[all][] = style.css
scripts[] = script.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment