Ok ci siamo quasi al risultato finale, ora ho messo a posto il codice e funziona quasi tutto, ho notato facendo varie prove che
tw = document.getElementById('table').width;
Non prende niente, i esce una variabile vuota per questo il risultato dell operazione
tl == (tw-widthWindow)
è tl == -1135(larghezza pagina)
Ti posto il codice intero mi devi solo aiutare a prende quel cavolo di width della tabella e poi quando lo prende trovo io il metodo in php di mettere automaticamente il width della tabella all'interno della tabella.
codice:
<html>
<head>
<script type="text/javascript">
widthWindow=screen.width;
//movimento derso destra
function move_right(){
z = setInterval("move()", 1);
}
function move(){
x = parseInt(document.getElementById('table').style.left);
if (x == 0)
clearInterval(z);
else
document.getElementById('table').style.left = (x+1)+"px";
}
function stop_right(){
clearInterval(z);
}
//movimento verso sinistra
function move_left(){
z = setInterval("move_()", 1);
}
function move_(){
tw = document.getElementById('table').width;
tl = parseInt(document.getElementById('table').style.left);
if(tl == (tw-widthWindow)){
clearInterval(z);
alert(tw);
}
else{
document.getElementById('table').style.left = (tl-1)+"px";
}
}
function stop_left(){
clearInterval(z);
}
</script>
</head>
<body style="overflow-x: hidden;">
<form method="post" action="upload_img.php" enctype="multipart/form-data">
Carica una nuova immagine nella gallery!
<input type="file" name="img" />
<input type="submit" value="carica" />
<input type="reset" value="reset" />
</form>
<?
//mi connetto al database
$archivio=mysql_connect("www.wordsbank.altervista.org", "wordsbank", "chesterfield");
$beta=mysql_select_db("my_wordsbank");
//ordino i campi in modo da avere gli ultimi caricati alla fine
$query=mysql_query("ALTER TABLE upload_img ORDER BY id ");
//query per la visualizzazione delle immagini
$query=mysql_query("SELECT * FROM upload_img");
//variabile vuota conterrà la lunghezza della tabella
echo "<table style=\"position:relative; width:1131; left:0;\" id=\"table\" border=\"0\">";
for ($i=0; $i < mysql_fetch_row($query); $i++){
$assoc=mysql_fetch_assoc($query);
$nome_img=mysql_result($query, $i, "nome_img");
$width=mysql_result($query, $i, "width");
$height=mysql_result($query, $i, "height");
$id=mysql_result($query, $i, "id");
//altezza new
$height_ = 155;
//larghezza new in scala
$width_ = (155*$width)/$height;
echo "
<td style=\"width:$width_; height:$height_;\">
<img style=\"cursor:pointer; position:relative; left:0px; top:0px;\" src=\"img/x.png\" onClick=\" document.location.href='del.php?id=$id';\" />
<img src=\"img/$nome_img\" width=\"$width_\" height=\"$height_\"/>
</td>
";
//incremento la lunghezza della tabell
$width_table = $width_table+$width_;
}
echo "</table>";
?>
<input id="<" type="submit" value="<" onmousedown="move_right();" onmouseup="stop_right();" />
<input id=">" type="submit" value=">" onmousedown="move_left();" onmouseup="stop_left();" />
</body>
</html>