- 浏览: 438922 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
ubuntu的疯狂:
推荐一份完整的教程:http://blog.ddlisting ...
Emberjs学习 -
ptz19:
请问,如果把合并前的文件,不要dest 目标目录来。如: js ...
gulp下静态资源的合并、压缩、MD5后缀 -
zhouzq1008:
楼主,还有个问题,<a href="" ...
gulp下静态资源的合并、压缩、MD5后缀 -
zhouzq1008:
感谢楼主,用到了您的代码, 但现在好像有改动 否则会报错:修改 ...
gulp下静态资源的合并、压缩、MD5后缀 -
denverj:
感谢分享~
Emberjs学习
<head> <script type="text/javascript"> function GetOffset (object, offset) { if (!object) return; offset.x += object.offsetLeft; offset.y += object.offsetTop; GetOffset (object.offsetParent, offset); } function GetScrolled (object, scrolled) { if (!object) return; scrolled.x += object.scrollLeft; scrolled.y += object.scrollTop; if (object.tagName.toLowerCase () != "html") { GetScrolled (object.parentNode, scrolled); } } // always return 1, except at non-default zoom levels in IE before version 8 function GetZoomFactor () { var factor = 1; if (document.body.getBoundingClientRect) { // rect is only in physical pixel size in IE before version 8 var rect = document.body.getBoundingClientRect (); var physicalW = rect.right - rect.left; var logicalW = document.body.offsetWidth; // the zoom level is always an integer percent value factor = Math.round ((physicalW / logicalW) * 100) / 100; } return factor; } function GetBox () { var div = document.getElementById ("myDiv"); if (div.getBoundingClientRect) { // Internet Explorer, Firefox 3+, Google Chrome, Opera 9.5+, Safari 4+ var rect = div.getBoundingClientRect (); x = rect.left; y = rect.top; w = rect.right - rect.left; h = rect.bottom - rect.top; if (navigator.appName.toLowerCase () == "microsoft internet explorer") { // the bounding rectangle include the top and left borders of the client area x -= document.documentElement.clientLeft; y -= document.documentElement.clientTop; var zoomFactor = GetZoomFactor (); if (zoomFactor != 1) { // IE 7 at non-default zoom level x = Math.round (x / zoomFactor); y = Math.round (y / zoomFactor); w = Math.round (w / zoomFactor); h = Math.round (h / zoomFactor); } } } else { // older Firefox, Opera and Safari versions var offset = {x : 0, y : 0}; GetOffset (div, offset); var scrolled = {x : 0, y : 0}; GetScrolled (div.parentNode, scrolled); x = offset.x - scrolled.x; y = offset.y - scrolled.y; w = div.offsetWidth; h = div.offsetHeight; } alert ("Left: " + x + "\nTop: " + y + "\nWidth: " + w + "\nHeight: " + h); } </script> </head> <body> <div style="height:200px; width:300px; overflow:auto;"> <div id="myDiv" style="width:250px; height:150px; border:1px solid red;"> You can get the bounding rectangle of this element relative to the top left corner of the client area with the button below.<br /> Use the scrollbars to test the placement of the bounding rectangle in different positions. </div> <div style="width:1000px; height:1000px;"></div> </div> <br /> <button onclick="GetBox ();">Get the placement of the element with red border!</button> </body>
发表评论
-
webpack简单打包PC网站前端资源
2016-02-23 14:30 1624:arrow: 1. 纯前端的打包输出,比较有局限 2 ... -
grunt构建基于seajs的网站实现
2015-06-16 16:49 1089Gruntfile.js module.exports ... -
js平滑滚动回到顶部
2015-06-10 11:42 3949优先使用 requestAnimationFrame实现。 实 ... -
fis-amd 的使用与修改
2015-05-26 16:14 3908https://github.com/fex-team/fis ... -
scrollMagic 视差与滚动动画GSAP
2015-05-19 18:14 4247scrollMagic(https://github.com/ ... -
skrollr-视差滚动动画插件
2015-05-19 14:18 1696skrollr ( https://github.com/Pr ... -
stellar插件的使用
2015-05-18 17:30 1671<!DOCTYPE html> < ... -
icon font VS svg font
2015-05-14 15:21 1156关于字体图标和SVG图标,CSS TRICK网站有较好的说明。 ... -
gulp下静态资源的合并、压缩、MD5后缀
2015-05-05 15:48 22528var gulp = require('gulp'); ... -
DOMContentLoaded VS onload VS onreadystatechange
2015-04-30 14:50 69361. DOMContentLoaded 在页面html、scr ... -
简单的css3全屏滚动
2015-04-27 16:41 1399<!DOCTYPE html> <ht ... -
jquery插件treetable 的使用
2015-04-20 16:12 11836插件的文档写得不是很好,为了能弄出异步加载的功能,小折腾了一番 ... -
sublime 侧边栏字体大小修改
2015-04-16 10:46 3778【转载自:http://jekhy.com ... -
移动端的“点透”问题
2015-04-15 14:13 1604移动端的“点透”问题,这篇博文有较好的说明: http://w ... -
scheme缺少,ie的bug
2015-04-01 17:34 499在页面上定位一个资源(JS/CSS/image),通常的url ... -
大整数相加
2015-03-26 22:18 878function repeatStr(ch, n){ ... -
window.name 跨域
2015-03-18 17:29 845window.name跨域的基础是:iframe页面在其url ... -
window.name 跨域
2015-03-18 17:27 1window.name跨域的基础是:iframe页面在其ur ... -
HTML History API
2015-03-13 18:05 1081// 替换当前浏览器history的最后一项记录。 hi ... -
Emberjs学习
2015-01-27 17:13 4048断断续续看了3周,还是一头雾水,文档不是很友好,这个框架,太多 ...
相关推荐
getBoundingClientRect
js getBoundingClientRect() 来获取页面元素的位置.docx
本文介绍这种组件的实现思路,并提供一个同时支持将sticky元素固定在顶部或底部的具体实现,由于这种组件在网站中非常常见,所以有必要掌握它的实现方式,以便在有需要的时候基于它的思路写出功能更多的组件出来
本文为大家介绍下如何使用getBoundingClientRect()方法获取元素距离浏览器周边的位置,有类似问题的朋友可以参考下哈,希望对你学习js有所帮助
1、getBoundingClientRect的作用 getBoundingClientRect用于获取某个html元素相对于视窗的位置集合。 执行 object.getBoundingClientRect();会得到元素的top、right、bottom、left、width、height属性,这些属性以一...
它返回一个对象,其中包含了left、right、top、bottom四个属性,分别对应了该元素的左上角和右下角相对于浏览器窗口(viewport)左上角的距离。 所以,网页元素的相对位置就是 var X= this.getBoundingClientRect()....
主要介绍getBoundingClientRect的基本属性,以及具体的使用场景和一些需要注意的问题。 getBoundingClientRect Element.getBoundingClientRect() 含义: 方法返回元素的大小及其相对于视口的位置。 值: 返回值...
js getBoundingClientRect使用方法详解.docx
请使用 element.getBoundingClientRect()。 经本人测试,确实是Firefox在含flash的网页上提示,还不知道原因,也没找到解决办法。 Firefox版本:3.0.3 Flash: 10.0 html页面代码: 代码如下:<html> <body&...
如何知道某个元素在视口中是否可见。 点击下面的链接查看博客文章
js中getBoundingClientRect( )方法案例详解.docx
js中getBoundingClientRect的作用及兼容方案详解.docx
用于 getBoundingClientRect 的 jQuery 插件助手 安装 $ bower install jquery.bounds --save 用法 $ ( 'div.mynode' ) . bounds ( ) ; 这将返回一个具有以下属性的对象: { top : 100 , left : 100 , ...
最近在做博客的目录功能,发现一个在现代浏览器间...此处应使用浏览器原生提供的 getBoundingClientRect 接口,此函数返回的是元素距离浏览器各边距的绝对位置,跟是什么定位类型的无关,非常适合制作页面滚动效果。