THIN_CS.prototype.getScrollPosition = function(e)
{
var b=e.document.body;
if(e==b)return {left:0,top:0};
with(e.getBoundingClientRect())
{
return {left:b.scrollLeft+left,top:b.scrollTop+top};
}
}

getBoundingClientRect在msdn的解释

Retrieves an object that specifies the bounds of a collection of TextRectangle objects. (返回一个对象包括所有TextRectangle的数组元素)

TextRectangle在msdn的解释

Specifies a rectangle that contains a line of text in either an element or a TextRange object.

来比较看一下getClientRects

Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client. Each rectangle describes a single line.

返回一个矩形框的数组,每一个数组表示单独一行,这里好像不是很准确,我们来看一段代码

<body>

<P >Four score and seven years ago
<!-- STYLE="position:absolute; width:200px;
height:100px; overflow:scroll"
οnclick=alert(this.scrollLeft+","+this.offsetTop+","+this.style.top+","+this.getBoundingClientRect().top)-->
<!--如果用了绝对/相对定位,则getClientRects()的数组元素为1而不是5-->

<B ID=oDiv ><img src="csdn.gif"> our fathers<BR>
brought forth . . . a new nation, conceived in liberty<BR>
and dedicated to the proposition that all men are<BR>
created equal.</B> Now we are engaged in a great civil war . . .
</P>

</body>
<script>
var s=document.getElementById("oDiv").getClientRects();
alert(s.length);
var b="";
for(var i=0;i<5;i++)
b+=s[i].left+",";
alert(b);

</script>

这段代码对B tag应用getClientRects()得到的TextRectangle Collection是5,而按照msdn中"single line"的理解应该是4

不过在thin的getScrollPosition函数中,我们并没有用到getClientRects()

对于getBoundingClientRect(),会返回一个object。

另外getBoundingClientRect()在msdn的remark

This method retrieves an object that exposes the left, top, right, and bottom coordinates of the union of rectangles relative to the client's upper-left corner. In Microsoft® Internet Explorer 5, the window's upper-left is at 2,2 (pixels) with respect to the true client.

也就是说返回的坐标是相对于2,2(pixels)也就是document.body的clientTop和clientLeft。

因此计算ScrollPosition我们要算上scrollLeft和scrollTop的值(这个对于计算两个object之间的距离时,必须用到),对于scrollLeft不明白可以查阅相关资料。

附上msdn中的位置表示的图片,对于理解element dimension 和 location十分有帮助

Technorati : DateChooser getBoundingClientRect getClientRects

Thin的DateChooser代码学习(getScrollPosition)(原创,转载请声明)相关推荐

  1. github 开源 代码 学习 集合(转载)

    一个支持多种item类型的recycleView依赖注入库 1.通过注解的方式方便的把ViewHolder注入到recycleView中. 2.去除findViewByID等冗余操作. 3.去除编写a ...

  2. c++builder实现文件拖拽与U盘复制---YYB原创(转载请注明出处)

    在这里我们使用到了一个API函数:DragQueryFile,它的原型如下: UINT DragQueryFile(    HDROP hDrop,    UINT iFile,    LPTSTR ...

  3. 使用IDEA打包war包,并部署到Tomcat中(原创转载请附上博文链接)

    前提 先完成https://blog.csdn.net/qq_23878541/article/details/90147223的5.1步骤. 因为5.1步骤是生成临时war目录,我们需要用此目录生成 ...

  4. PX4代码学习系列博客(6)——offboard模式位置控制代码分析(之前转载过,这是第二次转载了)

    我刚刚发现这篇文章去年八月份的时候转载过一次了 https://blog.csdn.net/sinat_16643223/article/details/107874349 转载自:https://b ...

  5. 翻译-高质量JavaScript代码书写基本要点(转载)

    by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/wordpress/?p=1173 原文作者:S ...

  6. pytorch cycleGAN代码学习1

    一. 新的东西 p.s :很多架构都和之前一样,就举些不同的 1. ReplayBuffer() # Buffers of previously generated samples   fake_A_ ...

  7. YOLO 卷积层代码学习

    YOLO 卷积层代码学习 卷积层的初始化 void im2col_cpu(float* data_im,int channels, int height, int width,int ksize, i ...

  8. (下)python3 selenium3 从框架实现代码学习selenium让你事半功倍

    上一篇博文简要 在上一篇博文中已得知:使用 execute 向远程服务器发送请求会通过 webdriver 与浏览器交互,且发送已定义的命令常量可获得一些相关信息. 其中 execute 方法实现已经 ...

  9. unity学习路线参考——转载自csdn

    版权声明: https://blog.csdn.net/qq_22521529/article/details/83108837 Unity3D学习路线与学习经验分享 作者:15游02 丁祺 你好,这 ...

最新文章

  1. ionic + cordova+angularJs 搭建的H5 App完整版总结
  2. ROS学习(二):在ubuntu 16.04安装ROS Kinetic
  3. Strut2判断是否是AJAX调用
  4. python-链表(学数据结构的同学可以看过来)
  5. 随便说说程序员团队精神的荣辱与共
  6. [HTTP] HTTP的缓存机制
  7. python常用模块用法_python笔记之常用模块用法分析
  8. VPP 命令总结(持续更新)
  9. golang的https服务器
  10. pci-e服务器显卡性能,PCI-E带宽揭密 显卡究竟能吃多大的带宽
  11. jinjia2 本地渲染文本文件核心代码(可以渲染html,xml,txt等等)
  12. 我也撸了一个古诗词网站
  13. 手写签名提取工具(图片)
  14. GitLab安装并设置为开机启动
  15. winform键盘操控之组合键
  16. Ajax案例之聊天机器人
  17. 旅行青蛙服务器维护时间,旅行青蛙小青蛙多久出门一次?要什么时候才会出门...
  18. 微信蓝牙设备服务器,微信又更新了 支持连接蓝牙设备
  19. 2022不一样的分享--行走的皮卡丘
  20. 3分钟学会使用Elasticsearch跨集群复制功能(CCR)

热门文章

  1. 用计算机计算最大公因数,利用计算器求两个较大数的最大公约数的简便方法
  2. linux ftp mysql_linux搭建ftp服务——未连接mysql数据库的做法
  3. 比特币的服务器作用,比特币白皮书解读-时间戳服务器
  4. 站长吧asp工具设置_网站更换域名需要怎么办?网站更换域名如何设置?
  5. linux 如何查看php的日志,Linux下apache日志分析与状态查看方法
  6. kafka分区和es的分区支持对比
  7. Visual Basic里与Print有关的函数
  8. 通过机房工作看软工之软工总结
  9. 谷歌CEO皮猜:我们想服务中国用户,但是没想好提供何种服务
  10. AI说:你的书法有咖喱味丨看字识国别