theforevernewb
11-08-2011, 03:58 PM
Roadblock: I am quickly getting over my head now...
I started with the Carousel Slideshow II script in the hopes of making a scrolling menu out of it. It kept looking wrong to me, and I realised that I wanted something different.
So I wrote this script that copies a DIV ID'd "locomotive" and creates two identical DIVs "railcar" and "caboose", and then assembles the train inside another DIV called "trainbox." It then scrolls the train inside the box either up or down depending on whether shift=1 or -1, at a speed defined by the delay variable. If you run the code, you should see what I mean if you run your mouse over the control links.
The problem I'm having is: I want to control this script by determining where on the outer div ("trainbox") the mouse cursor is positioned.
I've tried a bunch of invisible DIVs with mouseovers, but I can't click through them to get at the links in my scrolling menu. I have also tried setting the z-index of those invisible DIVs below the other objects, and that works a little bit but not well.
I want the train to move upwards when the mouse is near the top of "trainbox" and downwards when the mouse is near the bottom. I'd like to detect the cursor and change two variables according to the y position within the DIV. Can anyone help?
I'm a designer, not a coder, so take it easy on me. I'm sure the script below is a total mess... Oh... and I am forbidden from using external resources in my scripts.
<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>
I started with the Carousel Slideshow II script in the hopes of making a scrolling menu out of it. It kept looking wrong to me, and I realised that I wanted something different.
So I wrote this script that copies a DIV ID'd "locomotive" and creates two identical DIVs "railcar" and "caboose", and then assembles the train inside another DIV called "trainbox." It then scrolls the train inside the box either up or down depending on whether shift=1 or -1, at a speed defined by the delay variable. If you run the code, you should see what I mean if you run your mouse over the control links.
The problem I'm having is: I want to control this script by determining where on the outer div ("trainbox") the mouse cursor is positioned.
I've tried a bunch of invisible DIVs with mouseovers, but I can't click through them to get at the links in my scrolling menu. I have also tried setting the z-index of those invisible DIVs below the other objects, and that works a little bit but not well.
I want the train to move upwards when the mouse is near the top of "trainbox" and downwards when the mouse is near the bottom. I'd like to detect the cursor and change two variables according to the y position within the DIV. Can anyone help?
I'm a designer, not a coder, so take it easy on me. I'm sure the script below is a total mess... Oh... and I am forbidden from using external resources in my scripts.
<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>