Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Purple authored and Purple committed Apr 10, 2012
0 parents commit 3e9bd23
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script src="jquery.plaxmove.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<style>
html,body{height:100%;min-height:100%;overflow:hidden}
div{position:absolute;opacity:0.3}
.layer1{background:red;width:300px;height:150px;top:200px;left:300px}
.layer2{background:green;width:100px;height:200px;top:300px;left:900px}
.layer3{background:blue;width:50px;height:50px;top:550px;left:100px}
.layer1-shadow{background:#ccc;width:300px;height:150px;top:200px;left:300px}
.layer2-shadow{background:#ccc;width:100px;height:200px;top:300px;left:900px}
.layer3-shadow{background:#ccc;width:50px;height:50px;top:550px;left:100px}
</style>
</head>
<body>

<div class="layer1"></div>
<div class="layer2"></div>
<div class="layer3"></div>


<div class="layer1-shadow"></div>
<div class="layer2-shadow"></div>
<div class="layer3-shadow"></div>


<script type="text/javascript">
$(function(){
$('.layer1').plaxmove()
$('.layer2').plaxmove({ratioH:0.4,ratioV:0.4,reversed:true,invertH:false})
$('.layer3').plaxmove({ratioV:0.8,invertV:true})
});
</script>
</body>
</html>
77 changes: 77 additions & 0 deletions jquery.plaxmove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
(function($){
$.fn.plaxmove = function(options) {

this.defaults = {
ratioH: 0.2,
ratioV: 0.2,
invertH: false,
invertV: false,
reversed: false
}

var settings = $.extend({},this.defaults,options),
layer = $(this),
center = {
x: $('html').width()/2-layer.width()/2,
y: $('html').height()/2-layer.height()/2
},
y0 = layer.offset().top,
x0 = layer.offset().left;

if(settings.reversed) {

if(settings.invertH)
var eqH = function(e) {
return x0-(e.pageY - center.y)*settings.ratioH
}

else
var eqH = function(e) {
return x0+(e.pageY - center.y)*settings.ratioH
}

if(settings.invertV)
var eqW = function(e) {
return y0-(e.pageX - center.x)*settings.ratioV
}
else
var eqW = function(e) {
return y0+(e.pageX - center.x)*settings.ratioV
}

}

else {

if(settings.invertH)
var eqH = function(e) {
return x0-(e.pageX - center.x)*settings.ratioH
}

else
var eqH = function(e) {
return x0+(e.pageX - center.x)*settings.ratioH
}

if(settings.invertV)
var eqW = function(e) {
return y0-(e.pageY - center.y)*settings.ratioV
}
else
var eqW = function(e) {
return y0+(e.pageY - center.y)*settings.ratioV
}

}

$('html').on('mousemove', function(e) {

x = eqH(e)
y = eqW(e)

$(layer).css({top:y,left:x})

})

};
})(jQuery);

0 comments on commit 3e9bd23

Please sign in to comment.