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
广告
© . All rights reserved.