Tip: Click lines to highlight, hold ctrl/cmd to multi-select
http://codedumper.com/ifeva (17-Feb @ 17:31)
Syntax Highlighted Code
- // comment scroll
- var $form = $('#new_comment');
- if ( $form.length ) {
- var offset = $form.offset(),
- offsetTop = offset.top, offsetLeft = offset.left,
- fixedPos = false, timeout;
- $(window).bind('resize', function(event) {
- if ( timeout ) clearTimeout(timeout);
- timeout = setTimeout(resize, 50);
- function resize() {
- $form.css({
- position: 'relative',
- top: 0,
- left: 0,
- width: ''
- });
- offsetLeft = $form.offset().left;
- fixedPos = false;
- $(window).scroll();
- }
- });
- $(window).bind('scroll', function(event) {
- var scrollTop = $(this).scrollTop(),
- diff = scrollTop - offsetTop;
- if ( diff > -20 && !fixedPos ) {
- $form.css({
- position: 'fixed',
- top: 20,
- width: $form.width(),
- left: offsetLeft
- });
- fixedPos = true;
- } else if ( diff < -20 && fixedPos ) {
- $form.css({
- position: 'relative',
- top: 0,
- left: 0,
- width: ''
- });
- fixedPos = false;
- }
- }).scroll();
- }
Plain Code
// comment scroll
var $form = $('#new_comment');
if ( $form.length ) {
var offset = $form.offset(),
offsetTop = offset.top, offsetLeft = offset.left,
fixedPos = false, timeout;
$(window).bind('resize', function(event) {
if ( timeout ) clearTimeout(timeout);
timeout = setTimeout(resize, 50);
function resize() {
$form.css({
position: 'relative',
top: 0,
left: 0,
width: ''
});
offsetLeft = $form.offset().left;
fixedPos = false;
$(window).scroll();
}
});
$(window).bind('scroll', function(event) {
var scrollTop = $(this).scrollTop(),
diff = scrollTop - offsetTop;
if ( diff > -20 && !fixedPos ) {
$form.css({
position: 'fixed',
top: 20,
width: $form.width(),
left: offsetLeft
});
fixedPos = true;
} else if ( diff < -20 && fixedPos ) {
$form.css({
position: 'relative',
top: 0,
left: 0,
width: ''
});
fixedPos = false;
}
}).scroll();
}