// 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(); }