Created
July 31, 2014 23:58
-
-
Save leviwheatcroft/c9607aba440cc1fe0624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#test { | |
background-color: #000000; | |
background-image: url('http://placekitten.com/g/200/300'); | |
display: block; | |
width: 200px; | |
height: 1000px; | |
background-repeat: no-repeat; | |
margin: 100px 0 0 0; | |
background-attachment: fixed; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id='test'> | |
reference reference reference reference reference reference reference reference | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(jQuery) { | |
jQuery.fn.parallaxBackground = function(options) { | |
var defaults = { | |
offsetX: 0, | |
offsetY: 0, | |
ratio: 0.5 | |
}; | |
options = $.extend({}, defaults, options); | |
var top = this.offset().top; | |
var target = this; | |
$(window).scroll(function(event) { | |
console.log(event.originalEvent.pageY); | |
console.log(top); | |
console.log(options.ratio); | |
//console.log($('#test').offset().top); | |
var position = '0px ' + ((event.originalEvent.pageY - top) * options.ratio) + 'px'; | |
target.css('background-position', position); | |
console.log(position); | |
}); | |
return this; | |
}; | |
})(jQuery); | |
$(document).ready(function() { | |
$('#test').parallaxBackground(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment