Jump to content
php.lv forumi
  • 0

Javascript banner rotation scripts


laucinieks

Question

Skripts -

<script type="text/javascript">
var imgs1 = new Array("images/1.png","images/2.png","images/3.png");
var alt1 = new Array();
var currentAd1 = 0;
var imgCt1 = 3;
function cycle1() {
 if (currentAd1 == imgCt1) {
currentAd1 = 0;
 }
var banner1 = document.getElementById('adBanner1');
var link1 = document.getElementById('adLink1');
 banner1.src=imgs1[currentAd1]
 banner1.alt=alt1[currentAd1]
 currentAd1++;
}
 window.setInterval("cycle1()",3000);

</script>
<img src="images/1.png" id="adBanner1" border="0" width="180" height="220">

 

Kā var katrai bildei pievienot savādāku linku? Lai katras bildes linku varētu nodefinēt tāpat kā bildes atrašānās vietu, un mainoties bildei - mainās linki.

L.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Ērtāk jau būtu izmantot objektu, bet ja jau grib arrayu, tad kāpēc tad neturpini tā, kā jau esi uztaisījis?

var urls = ['www.php.lv', 'php.lv/f', 'paste.php.lv'];

un tad kodā aiz alt

banner1.parentNode.href = 'http://' + urls[currentAd1];

un htmlā

<a href="http://www.php.lv"><img src="images/1.png" id="adBanner1" border="0" width="180" height="220"></a>

Edited by indoom
Link to comment
Share on other sites

  • 0

indoom, taisot pēc tava varianta, banneri nemainās, kods -

<script type="text/javascript">
var imgs1 = new Array("./bilde1.jpg","http://www.opera.com/bitmaps/company/education/wsc_728x90.jpg","http://www.dep.state.fl.us/waste/quick_topics/publications/shw/recycling/ARD/2007/728X90_Banner.jpg");
var alt1 = new Array();
var urls = ['www.php.lv', 'php.lv/f', 'paste.php.lv'];
var currentAd1 = 0;
var imgCt1 = 3;
function cycle1() {
 if (currentAd1 == imgCt1) {
   	currentAd1 = 0;
 }
var banner1 = document.getElementById('adBanner1');
var link1 = document.getElementById('adLink1');
 banner1.src=imgs1[currentAd1]
 banner1.alt=alt1[currentAd1]
 banner1.parentNode.href = 'http://' + urls[currentAd1];
 currentAd1++;
}
 window.setInterval("cycle1()",3000);

</script>
<a href="http://www.php.lv"><img src="./bilde1.jpg" id="adBanner1" border="0" width="728" height="90"></a>

Edited by laucinieks
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...