Forum Moderators: open
o the way you do. As for grabbing the images, I would suggest creating a more flexible method, but if you are set on using scrolling as a transition you don't even need to access them, just the container. var interval=setInterval('slide()',15);
[...]
clearInterval(interval);
var interval=setInterval(slide,15);
count+=10;
o.style.left=count+'px';
<div id='slideshow'><div>
<img src='img1.jpg'/>
<img src='img2.jpg'/>
<img src='img3.jpg'/>
<img src='img4.jpg'/>
<img src='img5.jpg'/>
<img src='img6.jpg'/>
<img src='img7.jpg'/>
<img src='img8.jpg'/>
</div></div>
<a href='javascript:goTo(0); void 0;'>slide 0</a>
<a href='javascript:goTo(1); void 0;'>slide 1</a>
<a href='javascript:goTo(2); void 0;'>slide 2</a>
<a href='javascript:goTo(3); void 0;'>slide 3</a>
<a href='javascript:goTo(4); void 0;'>slide 4</a>
<a href='javascript:goTo(5); void 0;'>slide 5</a>
<a href='javascript:goTo(6); void 0;'>slide 6</a>
<a href='javascript:goTo(7); void 0;'>slide 7</a>
#slideshow {width:240px; height:180px; overflow:hidden;}
#slideshow div {width:10000px; position:relative;}
#slideshow img {float:left;}
//set speed variables
var animSpeed=1000;
var tickSpeed=3000;
//These values are hard-coded only as an example
var w=240,len=8;
//global variables
var container=document.getElementById('slideshow').childNodes[0],
animate,slideshow,slide=0,x=0;
//moves the slideshow to slide # i
function goTo(i) {
// if the animation is already running (due to
// a user's click) we don't want to run two both
// animations at once
clearInterval(animate);
// if the user changes the slide they should get
// as much time on that slide as if the script
// changed it
clearInterval(slideshow);
// position to move from
var _x=x;
// animation is based on time so it doesn't take too
// long on slow computers
var start=new Date().getTime();
// we don't need to name the function, but we do need
// to store the return value so it can be cancelled
animate=setInterval(function() {
// calculate p=progress
var p=(new Date().getTime()-start)/animSpeed;
// if progress>=100%, stop animating
if(p>=1) {
p=1;
clearInterval(animate);
}
// optional easing function
p=1-Math.pow(1-p,2);
//calculate new position
x=_x+p*(i*w-_x);
//apply position to slideshow
container.style.right=(x|0)+'px';
},15);
// restart the automatic progression
slideshow=setInterval(function() {
if(++slide==len)
slide=0;
goTo(slide);
},tickSpeed);
}
goTo(0);
//I eliminated almost all the timing and I don't call the //function twice, but still I don't think it will work, //what may be missing?
var animateSpeed =1000;
var tickSpeed = 8000;
var w = 340; len = 8;
var container=document.getElementById('slideshow').childNodes[0];
slide = 0, x = 0;
count = 0;
function goTo (slide)
{animate = setInterval (function {var_x = x;
x = slide*w-x; container.style.right = (x|0) + "px";
}, 16); count++; if (count == len) {clearInterval(animate);}
};
goTo(0); //Javascript
/* I understand that you call the internal clock of the computer only to have a shorter measure of the progress, which would equal 1 when the difference of time generates a number equal to the hundred percent, I also reckon this is an arbitrary measure of yours.
Not that I mind, though. However I don't understand what's going on: two functions are called simultaneously, and the second one, slideshow, is called only to measure how many times you have called it, from there the ++len? I think the slideshow function works as an end to the whole progression, but can't figure why. Obviously if I put the last line into the braces, the computer alerted me I was out of memory, because I'm calling the function over and over, isn't it? */
var animSpeed=1000;
var tickSpeed=8000;
//desired time to lapse
var w=340; len=8 //8 images 340 px wide
//global vars
var container=document.getElementById('slideshow').childNodes[0], animate,slideshow, slide=0, x=0;
//move to the desired slide
//from here the link can do its work, why the void value? (:
function goTo(i) {
//clear the inner interval, we don't want two animations running at once
clearInterval(animate);
//As you said the function must take the same time if the user had called it, I understand otherwise you'd stop one calling to the function and not both.
clearInterval(slideshow);
//initial pos
var _x = x;
var start=new Date().getTime();
//It isn't necessary to name the function but to store it so the interval can be cancelled
animate = setInterval(function() {
//p = progress
var p = (new Date().getTime()-start)/animateSpeed;
//si es 100% detener la animaci髇
if (p>=1) {
p=1; //safer to return this value to use less resources?
clearInterval(animate);}
//optional easing function
p=1-Math.pow(1-p, 2);
//new position
x = _x+p(i*w-_x); /*ere is where the div is animated, simply moving it n times (the number of slides multiplied by their width) to the right. But how does the interval work, simply doing it so quickly that you can't tell it's computing?*/
//Am I animating the div or the images, I figure out it's the div.
//Apply the position
container.style.right=(x|0)+"px";
}, 15); //shorter perceived interval in miliseconds
//What happens here with the whole of the multitude?
slideshow=setInterval(function() {
if (++slide==len)
slide=0;
goTo(slide);
}, tickSpeed);
}
goTo(0); //Why is it necessary to call the function from here, where am I
//calling the function, here or above? I reckon this is the function that calls when the page loads, the rest is called from the links, isn't it?
I'm not sure why you are pairing that condition with the clearInterval statement. The condition determines if you are on the last slide; to wrap around you would put "count=0;" in the brackets. The statement stops the current animation. This should be done inside the function called by setInterval, and surrounded by a condition to check if the animation is done. I had a variable "p", so I could know that if p>=1 then I should stop the animation. If you just want to increment x then your test could be "if(x>=slide*w)", since slide*w yields the x position you are moving towards.if (count == len) {
clearInterval(animate);
}
var w = 340;
var container=document.getElementById('slideshow').childNodes[0];
var count = 0, x = 0;
function goTo (slide) {
var animate = setInterval (function {
x+=10; // if you want to be able to go backwards you need to change this
if(x>=slide*w) {
clearInterval(animate);
}
container.style.right = (x|0) + "px";
}, 16);
}
// this is where you would increment "count"
// (I do it in the "slideshow" interval)
slideshow=setInterval(function() {
slide=slide+1;
if (slide==len) //if we're past the last slide
slide=0;
goTo(slide);
}, tickSpeed);
p=1; //safer to return this value to use less resources?
x = _x+p(i*w-_x); /*ere is where the div is animated, simply moving it n times (the number of slides multiplied by their width) to the right. But how does the interval work, simply doing it so quickly that you can't tell it's computing?*/
Am I animating the div or the images, I figure out it's the div.
What happens here with the whole of the multitude?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- saved from url=(0014)about:internet -->
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Decoration page</title>
<link rel="stylesheet" href="slideshow.css" type="text/css">
<script src="scripts/diapositivas.js" type="text/javascript"></script>
</head>
<body style="margin-left: 8px;">
<div id="slideshow">
<div>
<img src="activos/portfoliodeco1.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco2.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco3.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco4.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco5.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco6.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco7.jpg" alt="dise帽o de decoraci贸n">
<img src="activos/portfoliodeco8.jpg" alt="dise帽o de decoraci贸n"></div>
</div>
<div class="go">
<a href="javascript:goTo(0); void 0;">diapositiva 0</a>
<a href="javascript:goTo(1); void 0;">diapositiva 1</a>
<a href="javascript:goTo(2); void 0;">diapositiva 2</a>
<a href="javascript:goTo(3); void 0;">diapositiva 3</a>
<a href="javascript:goTo(4); void 0;">diapositiva 4</a>
<a href="javascript:goTo(5); void 0;">diapositiva 5</a>
<a href="javascript:goTo(6); void 0;">diapositiva 6</a>
<a href="javascript:goTo(7); void 0;">diapositiva 7</a>
</div>
</body></html>
/*This is only a reset stylesheet*/
* { margin: 0; padding: 0; text-decoration: none; font-size: 1em; outline: none; }
code, kbd, samp, pre, tt, var, textarea, input, select, isindex, listing, xmp, plaintext { font: inherit; font-size: 1em; white-space: normal; }
dfn, i, cite, var, address, em { font-style: normal; }
th, b, strong, h1, h2, h3, h4, h5, h6 { font-weight: normal; }
a, img, a img, iframe, form, fieldset, abbr, acronym, object, applet, table { border: none; }
table { border-collapse: collapse; border-spacing: 0; }
caption, th, td, center { text-align: left; vertical-align: top; }
body {line-height: 1;}
q { quotes: "" ""; }
ul, ol, dir, menu { list-style: none; }
sub, sup { vertical-align: baseline; }
a { color: inherit; }
hr { display: none; } /* we don't need a visual hr in layout */
font { color: inherit !important; font: inherit !important; color: inherit !important; } /* disables some nasty font attributes in standard browsers */
blink { text-decoration: none; }
nobr { white-space: normal; }
/*comienza hoja de estilo personalizada */
/*Personalized stylesheet begins*/
#slideshow {width:340px; height:275px;overflow:hidden;}
#slideshow img {float:left;}
.descrip {background: #CCCCCC; filter:alpha(opacity=60)
opacity:0.6; width:360px; line-height:150px; height:auto; color: #333333; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:small; z-index:200; position:relative; bottom:10px;
text-align:center; margin:0;}
#slideshow div {width:10000px; position:relative;}
a {text-align:center; line-height:30px;
background:#CC3300;width:200px; padding:5px; text-decoration:none; color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:small}
.footer p {font-size:x-small; text-align:center; font-family:Arial, Helvetica, sans-serif;}
//Javascript
var w=340;
var container=document.getElementById("slideshow").childnodes[0];
var count=0, x=0;
function goTo(slide) { // I guess all I need to do to prevent it from breaking down while its running if the user clicks a link in the meantime is include a clearInterval function to stop both intervals now
// clearInterval(animate); and
//clearInterval(slideshow);
var animate=setInterval(function() {x+=10;
if(x>=slide*w){clearInterval(animate)} container.style.right=(x|0)+"px" }, 16);
} // Here I should increase the count and include a function that progresses automatically, like slideshow();
There's a typo at the start of the javascript - you want element.childNodes, not .childnodes. Additionally, the childNodes list includes text objects - .childNodes[0] is the line break you put between "<div id='slideshow'>" and "<div>". You can either delete the line break or use .childNodes[1], whichever you prefer.<!doctype html>
<html>
<head>
[title, stylesheets, etc]
</head>
<body>
[page content]
<script type='text/javascript' src='script.js'></script>
</body>
</html>
<!doctype html>
<html>
<head>
<title>slideshow</title>
<style type='text/css'>
[css]
</style>
</head>
<body>
[html]
<script type='text/javascript'>
[javascript]
</script>
</body>
</html>