Skip to content

Instantly share code, notes, and snippets.

@omgmog
Created October 28, 2013 15:26
Show Gist options
  • Star 47 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save omgmog/7198844 to your computer and use it in GitHub Desktop.
Save omgmog/7198844 to your computer and use it in GitHub Desktop.
Simple parallax background scrolling with jQuery
$(function() {
var $el = $('.parallax-background');
$(window).on('scroll', function () {
var scroll = $(document).scrollTop();
$el.css({
'background-position':'50% '+(-.4*scroll)+'px'
});
});
});
.parallax-background {
background-image: url('http://placekitten.com/1000/1000');
background-position: 50% 0;
background-repeat: no-repeat;
-webkit-background-size: cover;
background-size: cover;
-moz-transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
@kingRayhan
Copy link

Thanks you so much

@amichel86
Copy link

Thanks! :)

@akshuvo
Copy link

akshuvo commented Feb 3, 2018

Great Thanks

@metamorph-online
Copy link

Man, you saved me couple of hours in searching and coding:) thank you!:)

@blackzoli
Copy link

Thanks!

@omgkotofey
Copy link

Thanks God I found your solution. It's great. +1

@minimit
Copy link

minimit commented Jul 19, 2018

better than full jquery plugins :)

@nachodd
Copy link

nachodd commented May 30, 2019

Excellent!!! thanks!!!

@walraymmo
Copy link

Works fine thanks!!!

@kesnel
Copy link

kesnel commented Dec 11, 2020

I love it !! it's simple and better than other full bg parallax plugins. Thank You !!

@shalomthegreat
Copy link

This is awesome :) better then a giant library I was gonna have to implement. Thanks! <3

@SoLoGHoST01
Copy link

How to fix this issue happening with this in Internet Explorer where there is white space when you scroll?

@philippogol
Copy link

worked well also for background elements/divs by editing the 50% for full values (pxs), great job!

@korsomang
Copy link

Thank you! If you have missing background image at the bottom when scrolled all the way down, you can reverse the increment to resolve this issue. 'background-position':'center '+(+.4*scroll)+'px'

@elinachar
Copy link

Thanks a lot!! Exactly what I was searching for!

@figarali
Copy link

Thank you so much, Simple Solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment