jdeegz
08-09-2008, 12:25 AM
hey guys, first timer here =D
trying to add some javascript to my online portfolio.
so im trying to make a gallery, where you can cycle through my images.
I figured i could accomplish this by creating a string array (named img) and using onClick functions to update your location in the array.
Below is currently what i have come up with.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language='javascript' type="text/javascript">
var img = new Array("razor1.jpg", "razor2.jpg");
var desc = new Array("a", "b");
var picindex = 1;
function next(){
if(document.getElementById) {
document.getElementById('placeholder').src = img[picindex];
document.getElementById('d').innerHTML = desc[picindex];
picindex=picindex+1;
if(picindex==img.length){
picindex=0;
}
return false;
} else {
return true;
}
}
function prev(){
if(document.getElementById) {
document.getElementById('placeholder').src = img[picindex];
document.getElementById('d').innerHTML = desc[picindex];
picindex=picindex-1;
if(picindex==img.length){
picindex=0;
}
return false;
} else {
return true;
}
}
</script>
<link rel="stylesheet" href="deco.css" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<div>
<img src="razor1.jpg" id="placeholder" alt="">
</div>
<div id="d">
a
</div>
<P><a href="#" onclick="next();" id="link">Next</a></p>
<P><a href="#" onclick="prev();" id="link">Back</a></p>
</div>
</body>
</html>
sorry if the code is too long!
You can view it in action over at my webpage.
Here (http://babel.massart.edu/~jdegruttola/images/id/razor/testthis.htm)
there is probably an easier way to do this entire project, if so, please enlighten me, but if this is going good here is my problem.
I want to be able to stop the onClick function once I reach the end of the array, or when I am at the beginning.(meaning, if i am at the end, the next button should not work)
Thank you in advance for your time!
trying to add some javascript to my online portfolio.
so im trying to make a gallery, where you can cycle through my images.
I figured i could accomplish this by creating a string array (named img) and using onClick functions to update your location in the array.
Below is currently what i have come up with.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language='javascript' type="text/javascript">
var img = new Array("razor1.jpg", "razor2.jpg");
var desc = new Array("a", "b");
var picindex = 1;
function next(){
if(document.getElementById) {
document.getElementById('placeholder').src = img[picindex];
document.getElementById('d').innerHTML = desc[picindex];
picindex=picindex+1;
if(picindex==img.length){
picindex=0;
}
return false;
} else {
return true;
}
}
function prev(){
if(document.getElementById) {
document.getElementById('placeholder').src = img[picindex];
document.getElementById('d').innerHTML = desc[picindex];
picindex=picindex-1;
if(picindex==img.length){
picindex=0;
}
return false;
} else {
return true;
}
}
</script>
<link rel="stylesheet" href="deco.css" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<div>
<img src="razor1.jpg" id="placeholder" alt="">
</div>
<div id="d">
a
</div>
<P><a href="#" onclick="next();" id="link">Next</a></p>
<P><a href="#" onclick="prev();" id="link">Back</a></p>
</div>
</body>
</html>
sorry if the code is too long!
You can view it in action over at my webpage.
Here (http://babel.massart.edu/~jdegruttola/images/id/razor/testthis.htm)
there is probably an easier way to do this entire project, if so, please enlighten me, but if this is going good here is my problem.
I want to be able to stop the onClick function once I reach the end of the array, or when I am at the beginning.(meaning, if i am at the end, the next button should not work)
Thank you in advance for your time!