Prototype - clonePosition() 方法



此方法根據可選引數選項,克隆了 source 元素在 element 上的位置和/或維度。

語法

element.clonePosition(source[, options]);

以下是可能的選項的列表 −

名稱 預設值 說明
setLeft true 將 source 的左 CSS 屬性克隆到 element 中。
setTop true 將 source 的頂部 CSS 屬性克隆到 element 中。
setWidth true 將 source 的寬度克隆到 element 中。
setHeight true 將 source 的寬度克隆到 element 中。
offsetLeft 0 element 的左 CSS 屬性的偏移量。
offsetTop 0 element 的頂部 CSS 屬性的偏移量。

返回值

一個 HTML 元素。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function clonePosition() {
            var firstElement = $('firstDiv');
            var secondElement = $('secondDiv');
            secondElement.clonePosition( firstElement);
         }
      </script>
   </head>

   <body>
      <p>Click Clone Position button to see the result.</p>
      <div id = "firstDiv">
         <p>This is first paragraph</p> 
      </div>

      <div id = "secondDiv">
         <p>This is second paragraph</p> 
      </div>
      <br />
      
      <input type = "button" value = "Clone Position" onclick = "clonePosition();"/>
   </body>
</html>

輸出

prototype_element_object.htm
廣告