| | |
Image Rotation w/Links
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2005
Posts: 10
Reputation:
Solved Threads: 1
I am building a site that has 3 main sections (Sec1, Sec2, Sec3) These 3 sections will be the main navigation going accross the top. On the home page will be a image approx 528 X 228. Each section will have a image relevant to the section. So when the user scrolls over the Sec1 navigation link that sections image will apear. An example of this can be seen here http://www.corkscrewsetc.com/
However, I would like each section pic to link to that section. I am using Javascript for this. Here is the code
Then inserting the image using [HTML] <img name=picture src="img/iamge_main.jpg" width="528" height="228" border="0">[/HTML]
The rotation works fine but I would like to add links to each image.
Thanks in advance for any suggestions.
However, I would like each section pic to link to that section. I am using Javascript for this. Here is the code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript" type="text/JavaScript"> var image1= new Image(); var image2= new Image(); var image3= new Image(); image1.src = "img/image1.jpg"; image2.src = "img/image2.jpg"; image3.src = "img/image3.jpg"; function doButtons(picimage) { eval("document['picture'].src = " + picimage + ".src");} </script>
Then inserting the image using [HTML] <img name=picture src="img/iamge_main.jpg" width="528" height="228" border="0">[/HTML]
The rotation works fine but I would like to add links to each image.
Thanks in advance for any suggestions.
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
I mean, just do what you are already doing. Modify your image tag to be within an anchor tag:
[html]<img name=picture src="img/iamge_main.jpg" width="528" height="228" border="0">[/html]
That's what you have now. Add an anchor (I also removed the "name" tag as it is deprecated, changing it to the "ID" tag, and wrapped the value in quotes).
[html]<a id="picture_link" href=""><img id="picture" src="img/iamge_main.jpg" width="528" height="228" border="0"></a>[/html]
There, now you have a link. To change the link destination, you'd revise your JavaScript: function (you have to revise it anyway to be compliant and use the "id" property instead of "name"):
[html]function doButtons(picimage)
{
document.getElementById('picture').src = picimage + ".src";
document.getElementById('picture_link').href = "http://www.daniweb.com";
}
[/html]
That should work, though I haven't tested it.
[html]<img name=picture src="img/iamge_main.jpg" width="528" height="228" border="0">[/html]
That's what you have now. Add an anchor (I also removed the "name" tag as it is deprecated, changing it to the "ID" tag, and wrapped the value in quotes).
[html]<a id="picture_link" href=""><img id="picture" src="img/iamge_main.jpg" width="528" height="228" border="0"></a>[/html]
There, now you have a link. To change the link destination, you'd revise your JavaScript: function (you have to revise it anyway to be compliant and use the "id" property instead of "name"):
[html]function doButtons(picimage)
{
document.getElementById('picture').src = picimage + ".src";
document.getElementById('picture_link').href = "http://www.daniweb.com";
}
[/html]
That should work, though I haven't tested it.
![]() |
Similar Threads
- image rotation (C)
- Rotation (Java)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Var value is not passed
- Next Thread: Ajax instant chat example to download with source code
Views: 5174 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets api blackjack browser bug captchaformproblem checkbox child class close cookies createrange() cursor date debugger dependent developer disablefirebug dom dropdown editor element embed engine events explorer ext file flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jump libcurl maps margin math matrixcaptcha media mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming progressbar rated runtime safari scriptlets scroll search security session shopping size software solutions star stars stretch synchronous tweet unicode web webkit webservice window wysiwyg \n






