Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    scrollbar e posizione di un elemento

    ciao ragazzi sono nuovo e avrei bisogno di un vostro aiuto!!!ho un div scrollabile con 40 campi text.vorei sapere come fare a sapere le coordinate giuste di uno di questi campi text al variare della scrollbar.in pratica schiacciando un pulsante vorrei avere le rispettive coordinate di uno dei campi text che variano al variare della scrollbar.posto qui il codice ciao a tutti


    <html>
    <head>
    <title>tabella</title>

    <SCRIPT type="text/javascript">



    function getPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
    while (obj.offsetParent) {
    curleft += obj.offsetLeft
    obj = obj.offsetParent;
    }
    }
    else if (obj.x)
    curleft += obj.x;
    alert(curleft);
    return curleft;
    }

    function getPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
    while (obj.offsetParent) {
    curtop += obj.offsetTop
    obj = obj.offsetParent;
    }
    }
    else if (obj.y)
    curtop += obj.y;
    alert(curtop);
    return curtop;
    }




    function saluta() {

    txtUno=document.uno.txtUno.value;
    txtQuattro=document.uno.txtQuattro.value;

    alert("HAI SCRITTO="+" "+txtQuattro);
    }
    </script>

    </head>
    <body>
    <form name="uno" action="">
    <center><div id="pippo" style="width:450px;height:80px; overflow-x:scroll; overflow-y:scroll;border:1px solid black;">

    <table cellpadding="4" cellspacing="1" width="120%" border=0>
    <tr>
    <td width=20%><input type="text" id="txtuno">
    </td>
    </tr>
    <tr>
    <td width=20%><input type="text" name="txtuno">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="txtuno">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" id="txtuno">
    </td>
    </tr>
    </div>
    <tr>
    <td width=20%><input type="text" name="5">
    </td>
    </tr>


    <tr>
    <td width=20%><input type="text" name="6">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="7">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="8">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="9">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="10">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="11">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="12">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="13">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="14">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="15">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="16">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="17">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="18">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="19">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="20">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="21">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="22">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="23">
    </td>
    </tr>


    <tr>
    <td width=20%><input type="text" name="24">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="25">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="26">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="27">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="28">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="29">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="30">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="31">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="32">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="33">
    </td>
    </tr>


    <tr>
    <td width=20%><input type="text" name="34">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="35">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="36">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="37">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="38">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="39">
    </td>
    </tr>

    <tr>
    <td width=20%><input type="text" name="40">
    </td>
    </tr>
    </table>
    </center>
    </form>





    </div>
    <center>
    <form action="">
    <input type="button" value="txtuno" onclick="javascript:getPosX(document.getElementByI d('txtuno'));javascript:getPosY(document.getElemen tById('txtuno'));" >
    <input type="button" value="txtuno" onclick="javascript:getPosX(document.getElementByI d('txtuno'));javascript:getPosY(document.getElemen tById('txtuno'));" >

    </form>
    </center>

    </body>
    </html>





  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    basta una sola discussione
    riportala su rispondendo anche solo "up"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.