// Find the left position of an element
function posX(elem) {
// Get the computed style and get the number out of the value
return parseInt( getStyle( elem, “left” ) );
}
// Find the top position of an element
function posY(elem) {
// Get the computed style and get the number out of the value
return parseInt( getStyle( elem, “top” ) );
}
获取style指定elem的值:
function getStyle( elem, name ) {
if (elem.style[name])
return elem.style[name];
//IE中的方法
else if (elem.currentStyle)
return elem.currentStyle[name];
// W3C的方法
else if (document.defaultView && document.defaultView.getComputedStyle) {
// It uses the traditional ‘text-align’ style of rule writing, instead of textAlign
name = name.replace(/([A-Z])/g,"-$1");
name = name.toLowerCase();
// Get the style object and get the value of the property (if it exists)
var s = document.defaultView.getComputedStyle(elem,"");
return s && s.getPropertyValue(name);
} else
return null;
}
找到elem在页面中水平X(left),垂直Y的值(top),offsetLeft方法在不同的浏览器有所不同。
// Find the X (Horizontal, Left) position of an element
function pageX(elem) {
var p = 0;
// We need to add up all of the offsets for every parent
while ( elem.offsetParent ) {
// Add the offset to the current count
p += elem.offsetLeft;
// and continue on to the next parent
elem = elem.offsetParent;
}
return p;
}
// Find the Y (Vertical, Top) position of an element
function pageY(elem) {
var p = 0;
// We need to add up all the offsets for every parent
while ( elem.offsetParent ) {
// Add the offset to the current count
p += elem.offsetTop;
// and continue on to the next parent
elem = elem.offsetParent;
}
return p;
}
找到elem距离去父元素的位置:
// Find the horizontal positioing of an element within its parent
function parentX(elem) {
// If the offsetParent is the element’s parent, break early
return elem.parentNode == elem.offsetParent ?
elem.offsetLeft :
// Otherwise, we need to find the position relative to the entire
// page for both elements, and find the difference
pageX( elem ) - pageX( elem.parentNode );
}
// Find the vertical positioing of an element within its parent
function parentY(elem) {
// If the offsetParent is the element’s parent, break early
return elem.parentNode == elem.offsetParent ?
elem.offsetTop :
// Otherwise, we need to find the position relative to the entire
// page for both elements, and find the difference
pageY( elem ) - pageY( elem.parentNode );
}
找到elem中style中left,top的值:
// Find the left position of an element
function posX(elem) {
// Get the computed style and get the number out of the value
return parseInt( getStyle( elem, “left” ) );
}
// Find the top position of an element
function posY(elem) {
// Get the computed style and get the number out of the value
return parseInt( getStyle( elem, “top” ) );
}
设置elem left,top的值:
// A function for setting the horizontal position of an element
function setX(elem, pos) {
// Set the ‘left’ CSS property, using pixel units
elem.style.left = pos + “px”;
}
// A function for setting the vertical position of an element
function setY(elem, pos) {
// Set the ‘left’ CSS property, using pixel units
elem.style.top = pos + “px”;
}
// A function for adding a number of pixels to the horizontal
// position of an element
function addX(elem,pos) {
// Get the current horz. position and add the offset to it.
setX( posX(elem) + pos );
}
// A function that can be used to add a number of pixels to the
// vertical position of an element
function addY(elem,pos) {
// Get the current vertical position and add the offset to it
setY( posY(elem) + pos );
}
获得元素的width,height,隐藏的元素是不可以获得width和height,可以用fullHeight,fullWidth实现:
// Get the actual height (using the computed CSS) of an element
function getHeight( elem ) {
// Gets the computed CSS value and parses out a usable number
return parseInt( getStyle( elem, ‘height’ ) );
}
// Get the actual width (using the computed CSS) of an element
function getWidth( elem ) {
// Gets the computed CSS value and parses out a usable number
return parseInt( getStyle( elem, ‘width’ ) );
}
// Find the full, possible, height of an element (not the actual,
// current, height)
function fullHeight( elem ) {
// If the element is being displayed, then offsetHeight
// should do the trick, barring that, getHeight() will work
if ( getStyle( elem, ‘display’ ) != ‘none’ )
return elem.offsetHeight || getHeight( elem );
// Otherwise, we have to deal with an element with a display
// of none, so we need to reset its CSS properties to get a more
// accurate reading
var old = resetCSS( elem, {
display: ‘’,
visibility: ‘hidden’,
position: ‘absolute’
});
// Figure out what the full height of the element is, using clientHeight
// and if that doesn’t work, use getHeight
var h = elem.clientHeight || getHeight( elem );
// Finally, restore the CSS properties back to what they were
restoreCSS( elem, old );
// and return the full height of the element
return h;
}
// Find the full, possible, width of an element (not the actual,
// current, width)
function fullWidth( elem ) {
// If the element is being displayed, then offsetWidth
// should do the trick, barring that, getWidth() will work
if ( getStyle( elem, ‘display’ ) != ‘none’ )
return elem.offsetWidth || getWidth( elem );
// Otherwise, we have to deal with an element with a display
// of none, so we need to reset its CSS properties to get a more
// accurate reading
var old = resetCSS( elem, {
display: ‘’,
visibility: ‘hidden’,
position: ‘absolute’
});
// Figure out what the full width of the element is, using clientWidth
// and if that doesn’t work, use getWidth
var w = elem.clientWidth || getWidth( elem );
// Finally, restore the CSS properties back to what they were
restoreCSS( elem, old );
// and return the full width of the element
return w;
}
// A function used for setting a set of CSS properties, which
// can then be restored back again later
function resetCSS( elem, prop ) {
var old = {};
// Go through each of the properties
for ( var i in prop ) {
// Remember the old property value
old[ i ] = elem.style[ i ];
// And set the new value
elem.style[ i ] = prop[i];
}
// Retun the set of changed values, to be used by restoreCSS
return old;
}
// A function for restoring the side effects of the resetCSS function
function restoreCSS( elem, prop ) {
// Reset all the properties back to their original values
for ( var i in prop )
elem.style[ i ] = prop[ i ];
分享到:
相关推荐
建筑工地扬尘治理与文明施工检查表.docx
基于java的个性化旅游攻略定制系统设计与实现.docx
数学建模培训资料 数学建模实战题目真题答案解析解题过程&论文报告 导弹追击模型的建立与求解 共6页.pdf
基础课程辅助教学-JAVA-基于springBoot程序设计基础课程辅助教学系统设计与实现
适用人群:大学生 自学者 使用场景:大学生毕设 自学者练手项目 学习与交流 其它说明:部分资源来源网络及开源社区、仅供参考与学习、不可商用、若有侵权请联系删除! 内容概要:用springmvc实现的校园选课管理系统
java课程期末考试
C++ Vigenère 密码(解密代码)
工程研究中心申报基本情况一览表.docx
Vigenère 密码(加密代码)
密码学AES算法源代码,密码学实验
基于java的百货中心供应链管理系统设计与实现.docx
环境说明:开发语言:Java 框架:springboot JDK版本:JDK1.8 服务器:tomcat7 数据库:mysql 5.7 数据库工具:Navicat 开发软件:eclipse/myeclipse/idea Maven包:Maven 浏览器:谷歌浏览器。 项目均可完美运行
【资源说明】 大数据毕业设计 基于Python+Spark机器学习天气预测系统详细文档+全部资料.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
购物系统 微信小程序+PHP毕业设计 源码+数据库+论文+启动教程
BIM 人才培养的框架和方法 相关的标准
源项目文件
ActiveMQ消息中间件的测试案例
内容概要:本文全面解析了汽车电动化、智能化背景下,车规芯片SoC的重要性和发展趋势。首先概述了汽车行业发展三大趋势——新能源车市场崛起、智能化引领新潮流、商业模式及价值链重构。随后详细介绍了车规芯片SoC的应用领域,包括主控芯片、功率芯片、CMOS芯片、射频接收器、传感器、存储芯片及汽车面板,并阐述了它们的作用和技术需求。文章接着讨论了电子电气架构的演进路径,从分布式向集中式的演进对汽车芯片供应链带来的影响。最后探讨了汽车SoC的技术特征、应用领域、未来发展方向及其面临的挑战。 适合人群:汽车芯片设计师、汽车制造商、科研机构及相关行业的专业人士。 使用场景及目标:理解和掌握汽车芯片尤其是SoC在智能电动汽车中的应用及未来发展,帮助相关从业者做出更好的技术和商业决策。 其他说明:随着智能电动汽车市场的快速成长,车规芯片SoC作为核心技术将面临前所未有的机遇和挑战。
用于控制 Broadlink RM2/3 (Pro) 遥控器、A1 传感器平台和 SP2/3 智能插头的 Python 模块python-broadlink用于本地控制 Broadlink 设备的 Python 模块和 CLI。支持以下设备通用遥控器RM home、RM mini 3、RM plus、RM pro、RM pro+、RM4 mini、RM4 pro、RM4C mini、RM4S、RM4 TV mate智能插头SP mini、SP mini 3、SP mini+、SP1、SP2、SP2-BR、SP2-CL、SP2-IN、SP2-UK、SP3、SP3-EU、SP3S-EU、SP3S-US、SP4L-AU、SP4L-EU、SP4L-UK、SP4M、SP4M-US、Ankuoo NEO、Ankuoo NEO PRO、Efergy Ego、BG AHC/U-01开关MCB1、SC1、SCB1E、SCB2出口BG 800, BG 900电源板MP1-1K3S2U、MP1-1K4S、MP2环境传感器A1报警套件S1C、S2KIT灯泡LB1、LB26 R1、LB2
这是一份关于五个城市的PM2.5监测数据文件,以CSV格式存储。数据涵盖了广州、北京、沈阳等地的空气质量情况,旨在帮助研究人员和数据分析人员更好地理解城市空气污染状况。 使用人群 适合对环境科学、大气污染研究感兴趣的科研工作者、学生及环保组织成员使用。 数据内容 包含五个主要城市的PM2.5浓度数据 时间跨度较长,覆盖多年数据 CSV格式方便导入各种数据分析软件进行进一步处理和分析