简体   繁体   中英

javascript image slider hyperlinks

I am working on a website and my client wants an image slider where each slide links to a different page on the site. I would prefer if this were to stay in Javascript as I cant seem to wrap my head around jquery. Here is my code

Javascript code in the header

`<script type="text/javascript">

<!-- 
var img1 = new Image()
img1.src="DowntownEventNew.jpg"
var img2 = new Image()
img2.src="Shakespeare.jpg"
var img3 = new Image()
img3.src="DowntownConcertNew.jpg"
var img4 = new Image()
img4.src="Rangerettes.jpg"
//-->
</script>

HTML 5 and Javascript in the body

 <div class="content">
      <div id="slide">
           <div class="slide_container">
<a href="Restaurants.html"><img src="DowntownEventNew.jpg" name="slide"  /> </a>
<script type="text/javascript">
<!--
var pic =1
function slides() {
if (!document.images)
return

document.images.slide.src=eval("img" +pic+".src")
if (pic < 4)
pic++

else
pic =1
setTimeout("slides()",5000)
}
slides()
//--> 
</script>

</div>
     </div>

Use a plugin like Nivo Slider (that way you don't really need to develop the jQuery from scratch), and then wrap the image in an anchor tag <a> :

<div id="slider">
    <img src="images/thing.jpg" alt="No Link" />
    <a href="http://www.cnn.com"><img src="images/thing2.jpg" title="Link!" /></a>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM