» »

Javascript - banner rotation random start

Javascript - banner rotation random start

levaky ::

LP!

Imam naslednjo skropto:
var used = 0;
var location_counter = 0;
var refresh_counter = 1;
var map = new Array();

function banner(a, b, c, d, e) {
	this.name = a;
	this.url = b;
	this.image = c;
	this.date = d;
	this.active = 1;
	this.oid = 0;
	if (e != '') {
		this.loc = e
	} else {
		this.loc = settings.default_ad_loc
	}
}

function show_banners(a) {
	location_counter = location_counter + 1;
	if (a != '' && a != undefined) {
		map[location_counter] = a
	} else {
		map[location_counter] = settings.default_ad_loc
	}
	var b = '<div id="' + settings.location_prefix + location_counter + '" class="' + settings.location_class + '"></div>';
	document.write(b);
	display_banners(location_counter)
}

function display_banners(a) {
	var b = new Array();
	if (a == '' || !a || a < 0) {
		return
	}
	var c = banners.length;
	if ((c == used) && settings.duplicate_banners == 0) {
		return
	}
	for (i = 0; i < (banners.length); i++) {
		banners[i].oid = i;
		if ((banners[i].loc == map[a]) && (banners[i].active == 1)) {
			b.push(banners[i])
		}
	}
	var d = Math.floor(Math.random() * b.length);
	var e = b[d];
	var f = (settings.force_size == 1) ? ' width="' + settings.img_width + '" height="' + settings.img_height + '"' : '';
	var g = '<a href="' + e.url + '" title="' + e.name + '" target="' + settings.window + '"><img border="0" src="' + e.image + '"' + f + ' alt="' + e.name + '" /></a>';
	var h = new Date();
	var j = e.date;
	j = j.split('/', 3);
	var k = new Date();
	k.setFullYear(parseInt(j[2]), parseInt(j[1]) - 1, parseInt(j[0]));
	if ((h < k) && e.active == 1) {
		var l = document.getElementById(settings.location_prefix + a);
		if (l == null) {
			alert('spyka Webmaster banner rotator\nError: adLocation doesn\'t exist!')
		} else {
			l.innerHTML = g;
			if (settings.duplicate_banners == 0) {
				banners[e.oid].active = 0;
				used++
			}
			return
		}
	} else {
		display_banners(a)
	}
	return
}

function refresh_banners() {
	if ((refresh_counter == settings.refresh_max) || settings.refresh_time < 1) {
		clearInterval(banner_refresh)
	}
	used = 0;
	for (j = 0; j < (banners.length); j++) {
		banners[j].active = 1
	}
	for (j = 1; j < (location_counter + 1); j++) {
		display_banners(j)
	}
	refresh_counter++
}
var banner_refresh = window.setInterval(refresh_banners, settings.refresh_time);


Če prav razumem, omenjena koda prikazuje vse bannerje v random zaporedju? Math.random se kliče vsakič, ko se zamenja banner?

Kam naj prestavim random funkcijo, da se bo zagnala samo, ko uporabnik prvič odpre stran. Se pravi, da začne rotirati bannerje na random poziciji, ampak jih potem rotira enega za drugim...

lp, Matej


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

jQuery - proži samo enkrat

Oddelek: Programiranje
71172 (969) luksorzi
»

1st web project... speed up?

Oddelek: Programiranje
172711 (2075) galu
»

[javaScript] Preverjanje formata zapisa EMŠO

Oddelek: Programiranje
132936 (2556) win64
»

kako film, ki se predvaja v brskalnuki prenesti na disk (strani: 1 2 )

Oddelek: Pomoč in nasveti
6717866 (10883) SLO_Matej
»

Internet strani kot slideshow

Oddelek: Izdelava spletišč
212110 (1861) sverde21

Več podobnih tem