0
我一直在尋找一個parallax mousemove script
有一天,發現這個腳本:
$(document).ready(function() {
$('#div1').mousemove(function (e) {
parallax(e, this, 0.5);
parallax(e, document.getElementById('div2'), 1);
parallax(e, document.getElementById('div3'), 1.5);
});
});
function parallax(e, target, layer) {
var layer_coeff = 10/layer;
var x = ($(window).width() - target.offsetWidth)/2 - (e.pageX - ($(window).width()/2))/layer_coeff;
var y = ($(window).height() - target.offsetHeight)/2 - (e.pageY - ($(window).height()/2))/layer_coeff;
$(target).offset({ top: y ,left : x });
};
* {
margin: 0;
padding: 0;
}
div {
position: absolute;
width: 100%;
height: 100%;
}
#div1 {
background-color: red;
}
#div2 {
background-color: orange;
}
#div3 {
background-color: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
<div id="div2"></div>
<div id="div3"></div>
</div>
現在我當鼠標不再徘徊在div1
上時,要將腳本重置爲默認位置。我怎麼做?
在此先感謝!
P.S.如果有更好的Script
爲此目的隨時發佈。