Friday, March 19, 2010

jQuery scroll to element

Here's a simple way to auto scroll to an element of the page really nice.

First you have to add this piece of code (of couse jQuery library must be included in your source code):

jQuery.fn.extend({
scrollTo : function(speed, easing) {
return this.each(function() {
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, speed, easing);
});
}
});

And then you just scroll to an element id:

$('#element_id').scrollTo(1000);

You can speed up the scrolling by reducing the scroll time. Eg. scrollTo(100)

Thursday, March 4, 2010

PHP log errors to log file

Logging PHP errors to a log file is critical. You don't want to display PHP errors or warnings to users, but to log all errors to a file that you can view. This way you can fix all errors, warnings, notices and the client won't see any PHP error.

You can easily do this by adding two lines at the beginning of your code:

ini_set('log_errors', 1);
ini_set('error_log', '/path-to/error_log.file');

You can use later any editor to view contents of your log file and fix all problems that occured.