u jayakodi
05-18-2013, 01:22 PM
U jayakodi
I have re-worked on the good old Carousel Slideshow code to make it look simpler and added dynamic features to change direction of rotation with the 4 arrow keys, change the speed with + - keys, move the carousel with PgUp / Dn keys and change the size with / * keys; the code is as given below and works well with IE for me.
<html><body></body>
<script type='text/javascript'>
pics=['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg']
// or, your list of images: pics=['c:/1.wmf','c:/2.wmf','c:/3.wmf','c:/4.wmf','c:/5.wmf']
var sides=8,speed=20,pw=100,drn="horiz",counter=0,spn=true,dn=1,mpi=Math.PI
pn=pics.length;if(sides>2*pn){sides=2*pn}
var px=[],imgx=[],imgy=[],imgw=[],ino,imn,faces,cnv
cnv=document.body.appendChild(document.createElement("div"))
with(cnv.style){width=pw;height=pw;position="absolute";left=pw;top=pw}
ino=pn+1;imn=2*pn;faces=Math.ceil(sides/2)
for(var i=0;i<pn;i++){px[i]=cnv.appendChild(document.createElement("image"))
px[i].src=pics[i];px[i+pn]=px[i];if(pn==faces){px[i+2*pn]=px[i]}
with (px[i].style){position='absolute';border="solid 1 blue"}}
function stg(){var fo=Math.floor(pw*Math.cos(mpi/sides)/Math.sin(mpi/sides)/2);var tpi=0.2*mpi/sides
for(i=0;i<=10*faces;i++){imgw[i]=pw*Math.sin(tpi*i)
imgx[i]=Math.floor(pw+dn*fo*Math.cos(tpi*i)-imgw[i]/2)}}
function rotate(){setTimeout('rotate()',speed);if(!spn){return}
if(++counter>=10){counter=0;if(++ino>=imn){ino=pn}}
px[ino-faces].style.left=-5000
for(var i=0;i<faces;i++){with(px[ino-i].style){if(drn=="vert"){top=imgx[counter+i*10];left=0;width=pw;height=imgw[counter+i*10]}
else{left=imgx[counter+i*10];top=0;height=pw;width=imgw[counter+i*10]}}}
cnv.focus()}
cnv.onmouseover=function(){spn=false}
cnv.onmouseout=function(){spn=true}
cnv.onkeyup=function(){kk=event.keyCode
switch(kk){case 40:dn=-1;drn="vert";break
case 38:dn=1;drn="vert";break
case 39:dn=-1;drn="horiz";break
case 37:dn=1;drn="horiz";break
case 107:speed=speed-10;if(speed<0){speed=0};break
case 109:speed=speed+10;break
case 34:cnv.style.left=cnv.offsetLeft+50;cnv.style.top=cnv.offsetTop+50;break
case 33:cnv.style.left=cnv.offsetLeft-50;cnv.style.top=cnv.offsetTop-50;break
case 106: pw=pw+20;break
case 111: pw=pw-20;break}
stg()}
stg()
rotate()
alert("Use arrow keys to change direction\n+ / - to change the speed\nPgUp/PgDn to move carousel\n * or / to change the size.\nmouseOver pauses spinning")
</script>
</html>
Happy coding for all.
I have re-worked on the good old Carousel Slideshow code to make it look simpler and added dynamic features to change direction of rotation with the 4 arrow keys, change the speed with + - keys, move the carousel with PgUp / Dn keys and change the size with / * keys; the code is as given below and works well with IE for me.
<html><body></body>
<script type='text/javascript'>
pics=['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg']
// or, your list of images: pics=['c:/1.wmf','c:/2.wmf','c:/3.wmf','c:/4.wmf','c:/5.wmf']
var sides=8,speed=20,pw=100,drn="horiz",counter=0,spn=true,dn=1,mpi=Math.PI
pn=pics.length;if(sides>2*pn){sides=2*pn}
var px=[],imgx=[],imgy=[],imgw=[],ino,imn,faces,cnv
cnv=document.body.appendChild(document.createElement("div"))
with(cnv.style){width=pw;height=pw;position="absolute";left=pw;top=pw}
ino=pn+1;imn=2*pn;faces=Math.ceil(sides/2)
for(var i=0;i<pn;i++){px[i]=cnv.appendChild(document.createElement("image"))
px[i].src=pics[i];px[i+pn]=px[i];if(pn==faces){px[i+2*pn]=px[i]}
with (px[i].style){position='absolute';border="solid 1 blue"}}
function stg(){var fo=Math.floor(pw*Math.cos(mpi/sides)/Math.sin(mpi/sides)/2);var tpi=0.2*mpi/sides
for(i=0;i<=10*faces;i++){imgw[i]=pw*Math.sin(tpi*i)
imgx[i]=Math.floor(pw+dn*fo*Math.cos(tpi*i)-imgw[i]/2)}}
function rotate(){setTimeout('rotate()',speed);if(!spn){return}
if(++counter>=10){counter=0;if(++ino>=imn){ino=pn}}
px[ino-faces].style.left=-5000
for(var i=0;i<faces;i++){with(px[ino-i].style){if(drn=="vert"){top=imgx[counter+i*10];left=0;width=pw;height=imgw[counter+i*10]}
else{left=imgx[counter+i*10];top=0;height=pw;width=imgw[counter+i*10]}}}
cnv.focus()}
cnv.onmouseover=function(){spn=false}
cnv.onmouseout=function(){spn=true}
cnv.onkeyup=function(){kk=event.keyCode
switch(kk){case 40:dn=-1;drn="vert";break
case 38:dn=1;drn="vert";break
case 39:dn=-1;drn="horiz";break
case 37:dn=1;drn="horiz";break
case 107:speed=speed-10;if(speed<0){speed=0};break
case 109:speed=speed+10;break
case 34:cnv.style.left=cnv.offsetLeft+50;cnv.style.top=cnv.offsetTop+50;break
case 33:cnv.style.left=cnv.offsetLeft-50;cnv.style.top=cnv.offsetTop-50;break
case 106: pw=pw+20;break
case 111: pw=pw-20;break}
stg()}
stg()
rotate()
alert("Use arrow keys to change direction\n+ / - to change the speed\nPgUp/PgDn to move carousel\n * or / to change the size.\nmouseOver pauses spinning")
</script>
</html>
Happy coding for all.