PDA

View Full Version : Problema con javascript, funziona ma non in pagina php


badbrizio
19-10-2010, 10:54
Ciao a tutti, spero di aver postato nella sezione giusta ... vorrei utilizzare lo script nei tag code in un sito in php ma ho incontrato un problema che non riesco a risolvere.
Allora, il codice č questo, FUNZIONA, se lo provate č ok.

<html>
<head>
<title>Banner scorrevoli</title>
<script>
function clip()
{
var contWidth = 125; var contHeight = 800;
var id1 = document.getElementById('slideA');
var id2 = document.getElementById('slideB');
var height = id1.offsetHeight;
id1.style.top = parseInt(id1.style.top)-1 + 'px';
document.getElementById('slideCont').style.height = contHeight + "px";
document.getElementById('slideCont').style.clip = 'rect(auto,'+ contWidth +'px,' + contHeight +'px,auto)';
id2.style.display = '';
if(parseFloat(id1.style.top) == -(height/2)) {id1.style.top = '0px';}
setTimeout(clip,50)
}
function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function') {window.onload = func;}
else{window.onload = function() {if (oldonload) {oldonload();}func();}}
}
addLoadEvent(function() {clip();});
</script>
</head>
<body>
<table border="1" width="125" height="800">
<tr>
<td width="125">
<div id="slideCont" style="position:relative;z-index:1;width:125px;overflow:hidden;">
<div id="slideA" style="position:absolute;z-index:1;top:0px;left:0px;width:125px;overflow:hidden;">
<a href="#"><img src="1.gif" border="0"></a><br><br>
<a href="#"><img src="2.gif" border="0"></a><br><br>
<a href="#"><img src="3.gif" border="0"></a><br><br>
<a href="#"><img src="4.gif" border="0"></a><br><br>
<a href="#"><img src="5.gif" border="0"></a><br><br>
<a href="#"><img src="6.gif" border="0"></a><br><br>
<div id="slideB" style="position:relative;z-index:1;top:0px;left:0px;width:125px;overflow:hidden;">
<a href="#"><img src="1.gif" border="0"></a><br><br>
<a href="#"><img src="2.gif" border="0"></a><br><br>
<a href="#"><img src="3.gif" border="0"></a><br><br>
<a href="#"><img src="4.gif" border="0"></a><br><br>
<a href="#"><img src="5.gif" border="0"></a><br><br>
<a href="#"><img src="6.gif" border="0"></a><br><br>
</div>
</div>
</div>
</td>
</tr>
</table>
</body>
</html>

Allora, la pagina php che deve contenere questo script č cosė impostata:

pagina.php
<? include("code.php") ;?>
<? code1(); ?>
<title>titolo</title>
<? code2(); ?>
<table>contenuto</table>
<? code3(); ?>

code.php
<? function code1() { ?>
<html>
<head>
<meta>
<? } function code2() { ?>
<style></style>
<script>quello di sopra</script>
</head>
<body>
<? } function code3() { ?>
qui ci va il table con lo script
</body>
</html>
<? } ?>
Il problema č che cosė le immagini che dovrebbero scorrere non si vedono, non si vedono neanche fisse, tabella vuota.
Cosa devo fare per risolvere il problema?
Sono giorni che ci lavoro ma non riesco a trovare iuna soluzione, spero che qualcuno possa gentilmente aiutarmi.
Grazie.
Fabrizio.

badbrizio
21-10-2010, 13:39
Ok, sono riuscito a trovare il problema ... era nel body onload di un menu che andava messo in function addLoadEvent(func)