div移動到指定元素位置


1、html部分

1 <!--指定元素-->
2 <div id="div1" style="margin: 500px 0px 0px 500px; width: 200px;"><input type="text" name="Name" /></div>
3 <!--顯示面板-->
4 <div id="Pannel" style="display: none; position: absolute; border: 1px solid #e1e1e1;">
5 <h1>內容部分</h1>
6 </div>
View Code

2、js部分

 1    $("input[name='Name']").on("click", function () {
 2             //獲取當前元素
 3             var elem = $(this);
 4             var tops = elem.offset().top + elem[0].offsetHeight;
 5             //設置當前元素的寬、距離瀏覽器頂部、距離瀏覽器左邊
 6             $("#Pannel").css({
 7                 width: (elem[0].offsetWidth + 50) + "px",
 8                 height:'200px',
 9                 top: tops + "px",
10                 left: elem.offset().left + "px"
11             }).show();
12         });
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM