PDA

View Full Version : layer glider


stv
10-10-2002, 06:05 PM
I have a script from alchemy dhtml (many thanks)

That will glide alayer into position its fantastic!

I have an iframe and i am controlling a layer in that iframe from the main html page - all works fine (well in IE only at the moment!) except the function is always being called, i was wondering if anyone could assist me in stopping the function once the layer has returned to the location i want it to!


showcase is the iframe name, scroller the layer and scrollleft is the variable that i wish the layer to move to
heres the code::

function glide(steps) {
// changing this number will vary the amount of gliding
var decrease = 0.05;
if (document.all){
el = document.showcase.document.all['scroller'].style;
} else {
el = frames['showcase'].document.getElementById('scroller').style;
}
// you can change references to left in the script to top and that will give a vertical animation
el.xpos = parseInt(el.left);
el.ypos = parseInt(el.top);
if (el.xpos < scrollleft) {
distance = scrollleft - el.xpos;
steps = distance*decrease;
// to shove a layer off screen change to
// el.xpos -= steps;
el.xpos += steps;
el.left = el.xpos;
// change the 30 value to increase or decrease speed, higher the numeric value the slower the speed
setTimeout("glide('" + el + "'," + scrollleft + "," + steps + ")",30);
}
if (el.ypos < scrolltop) {
distancey = scrolltop - el.ypos;
stepsy = distance*decrease;
// to shove a layer off screen change to
// el.xpos -= steps;
el.ypos += stepsy;
el.top = el.ypos;
// change the 30 value to increase or decrease speed, higher the numeric value the slower the speed
setTimeout("glide('" + el + "'," + scrolltop + "," + steps + ")",30);
}
}

:: thanks a lot people
steve

Mr J
10-10-2002, 07:24 PM
I think you need to assign a stop position.

Give your timer a name.



Timer =setTimeout("glide('" + el + "'," + scrolltop + "," + steps + ")",30);



Then include


if(el.ypos==stop position){
clearTimeout(Timer)
el.pos=stop position // takes care of any overrun
}

Depending which way you are scrolling it might be best using

<=

OR

>=

in place of

==

within

el.ypos==stop position




Take a look at my scrolling layers on

www.huntingground.freeserve.co.uk/style/lyr_left.htm