function px(x) { return x + 'px' }

$(document).ready(function() {

  $('.scroll-to').each(function() {
    el = $(this);
    
    el.click(function(e) {
      target = $($(this).attr('href'));
      if (target.offset()) {
        $('html, body').animate({scrollTop: px(target.offset().top)}, 500); 
      }
      e.preventDefault();
      
    });
  });
  
});
