I was able to create the effect that you wanted in the violin:
http://jsfiddle.net/t0nyh0/8QTYt/36/
Important options
- A “fixed” full-size and full-sized wrapper that contains all of your moving elements helps you animate the div more consistently based on the scroll position (which is actually a “keyframe number”).
scroll_max, wrapper_width wrapper_height . / , / .- " ", .
- ,
top left. bottom right. , , , $window.scrollTop() " ".
HTML
<div id="wrapper">
<div id="a">
<h1>Meats</h1>
</div>
<div id="b">
<h1>Veggies</h1>
<hr/>
<p>Veggies sunt bona vobis, proinde vos postulo esse magis daikon epazote peanut chickpea bamboo shoot rutabaga maize radish broccoli rabe lotus root kohlrabi napa cabbage courgette mustard squash mung bean.</p>
</div>
</div>
CSS
body
{
height: 1000px; // 1000 keyframes
}
{
width: 100%;
height: 100%;
position: fixed;
border: 2px solid navy;
overflow:hidden;
}
position:absolute;
background-color: #daf1d7;
width: 300px;
height: 300px;
}
{
position: absolute;
background-color: #d2d0ee;
width: 200px;
height: 200px;
bottom: 0px;
right: 0px;
}
Javscript
var $window = $(window);
var $a = $('#a');
var $b = $('#b');
var scroll_max = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var wrapper_height = $('#wrapper').height();
var wrapper_width = $('#wrapper').width();
$window.scroll(function() {
console.log(scroll_max);
$a.css({
'top': ($window.scrollTop() / scroll_max) * wrapper_height,
'left': ($window.scrollTop() / scroll_max) * wrapper_width
});
$b.css({
'bottom': ($window.scrollTop() / scroll_max) * wrapper_height,
'right': ($window.scrollTop() / scroll_max) * wrapper_width
});
});