There actually is a way to create a dead zone in the center, and then calculate the speed progressively upon how far up or down you are from that zone, see the motionengine function in the motiongallery2.js file of:
http://www.dynamicdrive.com/dynamici...ongallery2.htm
But for now I chose to just go with what you already had:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Carousel Menu - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
#trainbox {
border: 1px solid red;
}
</style>
</head>
<body>
<script type='text/javascript'>
var height=70; //set this to the total height of items in locomotive.
var trainboxheight= 50; //visible (set smaller or equal to above).
var width=180; //set to width of widest item.
var delay=20; //time between steps in msec.
var shift=1; //+1 moves the train up, -1 moves it down.
var dreset=delay;
var turbo=delay/4;
var brakes=delay*4;
var shiftreset=shift;
var hreg=height*2;
var loco = null;
var cars = null;
var cabo = null;
var trainbox = null;
function smartMove(){
if (shift!=0 && hreg==0) {
loco.style.top = 0-height+'px';
cars.style.top = '0px';
cabo.style.top = 0+height+'px';
hreg=height*2;
} else if (shift!=0 && hreg==height) {
cars.style.top = 0-height+'px';
cabo.style.top = '0px';
loco.style.top = 0+height+'px';
} else if (shift!=0 && hreg==height*2) {
loco.style.top = 0-height+'px';
cars.style.top = '0px';
cabo.style.top = 0+height+'px';
} else if (shift!=0 && hreg==height*3) {
cabo.style.top = 0-height+'px';
loco.style.top = '0px';
cars.style.top = 0+height+'px';
} else if (shift!=0 && hreg==height*4) {
loco.style.top = 0-height+'px';
cars.style.top = '0px';
cabo.style.top = 0+height+'px';
hreg=height*2;
}
loco.style.top = parseInt(loco.style.top)-shift+'px';
cars.style.top = parseInt(cars.style.top)-shift+'px';
cabo.style.top = parseInt(cabo.style.top)-shift+'px';
hreg=hreg-shift;
setTimeout (smartMove,delay);
}
function init() {
trainbox = document.getElementById('trainbox');
trainbox.style.height = trainboxheight+'px';
trainbox.style.width = width+'px';
trainbox.style.position = 'relative';
trainbox.style.overflow = 'hidden';
loco = document.getElementById('locomotive');
cloner = loco.cloneNode(true);
cloner.setAttribute('id', 'railcar');
trainbox.appendChild(cloner);
cars = document.getElementById('railcar');
clonertwo = loco.cloneNode(true);
clonertwo.setAttribute('id', 'caboose');
trainbox.appendChild(clonertwo);
cabo = document.getElementById('caboose');
loco.style.width = width+'px';
loco.style.position = 'absolute';
loco.style.top = 0-height+'px';
cars.style.width = width+'px';
cars.style.position = 'absolute';
cars.style.top = '0px';
cabo.style.width = width+'px';
cabo.style.position = 'absolute';
cabo.style.top = height+'px';
smartMove();
}
window.onload = init;
</script>
<div id='trainbox'>
<div id='locomotive'>
<a href='http://localhost/'>usually are</a><br>
<a href='http://localhost/'>image links</a>
</div>
</div>
<a onmouseover="shift=1;delay=turbo;">faster up</a><br>
<a onmouseover="shift=1;delay=dreset;">normal up</a><br>
<a onmouseover="shift=1;delay=brakes;">extra slow up</a><br>
<a onmouseover="shift=0;delay=dreset;">full stop</a><br>
<a onmouseover="shift=-1;delay=brakes;">extra slow dn</a><br>
<a onmouseover="shift=-1;delay=dreset;">normal dn</a><br>
<a onmouseover="shift=-1;delay=turbo;">faster dn</a>
<script type="text/javascript">
document.getElementById('trainbox').onmousemove = function(e){
e = e || event;
var offsetel = document.getElementById('trainbox'),
offset = offsetel.offsetTop, h = offsetel.offsetHeight, y = e.clientY, zone = h / 8,
pagey = typeof pageY === 'number'? pageY :
document[document.compatMode === 'CSS1Compat'? 'documentElement' : 'body'].scrollTop;
while((offsetel = offsetel.offsetParent)){
offset += offsetel.offsetTop;
}
y -= offset - pagey;
if(y < zone){
shift=1;delay=turbo;
} else if (y < 2 * zone){
shift=1;delay=dreset;
} else if (y < 3 * zone){
shift=1;delay=brakes;
} else if (y < 4 * zone){
shift=0;delay=dreset;
} else if (y < 5 * zone){
shift=-1;delay=brakes;
} else if (y < 6 * zone){
shift=-1;delay=dreset;
} else {
shift=-1;delay=turbo;
}
};
document.getElementById('trainbox').onmouseout = function(e){
e = e || event;
var rt = e.relatedTarget || e.toElement, tb = document.getElementById('trainbox');
if(rt && rt === tb){
return;
}
while (rt && (rt = rt.parentNode)){
if(rt && rt === tb){
return;
}
}
shift=1;delay=dreset;
}
</script>
</body>
</html>
Notes: I didn't change or even look at your code. I simply added mine at the bottom there using your control variables (shift and delay) copied directly from your control links. Oh, and I added some HTML to make it a valid page, and a border to the trainbox so it would be easier to see when the mouse was over it. Probably would have been fine without those. Any questions though, feel free to ask.
Bookmarks