Skip to content

Instantly share code, notes, and snippets.

@anteprimorac
Created January 23, 2015 15:06
Show Gist options
  • Select an option

  • Save anteprimorac/5ba71412f93db35ca83e to your computer and use it in GitHub Desktop.

Select an option

Save anteprimorac/5ba71412f93db35ca83e to your computer and use it in GitHub Desktop.
;( function( $ ) {
var $background,
mouse = {
x: 0, // Current x-axis position of mouse
y: 0 // Current y-axis position of mouse
};
$( document ).on( 'mousemove', function( event ) {
mouse.x = event.clientX || event.pageX;
mouse.y = event.clientY || event.pageY;
if ( $background && $background.length )
$background.css( {
'transform': 'translate( ' + ( ( $( window ).width() / 2 - mouse.x ) / $( window ).width() * 100 ) + 'px, ' + ( ( $( window ).height() / 2 - mouse.y ) / $( window ).height() * 100 ) + 'px )'
} );
} );
$( document ).on( 'ready', function() {
$background = $( '.background-wrapper' );
} );
} ) ( jQuery )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment