jQuery 位置函数offset,innerWidth,innerHeight,outerWidth,outerHeight,scrollTop,scrollLeft_jquery

复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery的位置函数(offset(),innerWidth(),innerHeight(),outerWidth(),outerHeight(),scrollTop(),scrollLeft())小应用</title>
<style type="text/css">
#divShow{width:100px;height:50px;background-color:Green;display:none;}
#divAd{width:100px;height:100px;background-color:Red;position:absolute;top:100px;left:100px;}
</style>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
//在文本框下方显示一个div,类似日历控件那样。
function showDiv(obj){
jQuery("#divShow").css("left",jQuery(obj).offset().left);
jQuery("#divShow").css("top",jQuery(obj).offset().top + jQuery(obj).outerHeight());

jQuery("#divShow").show();
}
jQuery(function(){

});
//滚动条滚动,执行下面的函数,适合做浮动广告
jQuery(this).scroll(function(){
jQuery("#divAd").css("top",100 + jQuery(document).scrollTop());
jQuery("#divAd").css("left",100 + jQuery(document).scrollLeft());
});
</script>
</head>
<body>
<input type="text" value="ok" onclick="showDiv(this);" />
<div id="divShow">2010-03-22</div>
<div id="divAd">浮动广告</div>
<div style="height:2000px;width:2000px;">用来撑出滚动条</div>
</body>
</html>

时间: 2024-07-29 11:47:27

jQuery 位置函数offset,innerWidth,innerHeight,outerWidth,outerHeight,scrollTop,scrollLeft_jquery的相关文章

jQuery 位置函数实例教程

jQuery 位置函数实例教程 详细出处参考:.net教程/article/22685.htm">http://www.111cn.net/article/22685.htm <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xm

jQuery height()、innerHeight()、outerHeight()函数的区别详解_jquery

在jQuery中,获取元素高度的函数有3个,它们分别是height(). innerHeight(). outerHeight(). 与此相对应的是,获取元素宽度的函数也有3个,它们分别是width(). innerWidth(). outerWidth(). 在这里,我们以height().innerHeight().outerHeight()3个函数为例,来详细介绍它们之间的区别. 下面我们以元素element的盒模型为例来介绍它们之间的区别. 函数 高度范围 jQuery版本 支持写操作

深入分析jQuery height()、innerHeight()、outerHeight()函数的区别

在jQuery中,获取元素高度的函数有3个,它们分别是height(). innerHeight(). outerHeight(). 与此相对应的是,获取元素宽度的函数也有3个,它们分别是width(). innerWidth(). outerWidth(). 在这里,我们以height().innerHeight().outerHeight()3个函数为例,来详细介绍它们之间的区别. 下面我们以元素element的盒模型为例来介绍它们之间的区别. 函数 高度范围 jQuery版本 支持写操作

jQuery获得包含margin的outerWidth和outerHeight的方法

 这篇文章主要介绍了jQuery获得包含margin的outerWidth和outerHeight的方法,涉及jQuery中outerWidth及outerHeight方法的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下     本文实例讲述了jQuery获得包含margin的outerWidth和outerHeight的方法.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

jQuery获得包含margin的outerWidth和outerHeight的方法_jquery

本文实例讲述了jQuery获得包含margin的outerWidth和outerHeight的方法.分享给大家供大家参考.具体如下: <!DOCTYPE html> <html> <head> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(fun

jquery中offset()方法使用示例

jQuery 1.2 新增该函数. jQueryObject.offset( [ coordinates ] ) 注意: 1.如果省略了coordinates参数,则表示获取偏移位置:如果指定了该参数,则表示设置偏移位置.2.offset()函数的"设置"操作针对的是当前jQuery对象所匹配的每一个元素:"读取"操作只针对第一个匹配的元素. 1.获得元素相对于document的位置 获得位置是元素相对于document的位置信息,通常可以说是这个元素的坐标值. /

jQuery中offset()方法用法实例_jquery

本文实例讲述了jQuery中offset()方法用法.分享给大家供大家参考.具体分析如下: 此方法返回或设置所匹配元素相对于document对象的偏移量. 语法结构一: 复制代码 代码如下: $(selector).offset() 获取匹配元素在当前document的相对偏移. 返回的对象包含两个整型属:top和left. 此方法只对可见元素有效. 实例代码: 复制代码 代码如下: <!DOCTYPE html> <html> <head> <meta char

Jquery中offset()和position()的区别分析_jquery

本文实例分析了Jquery中offset()和position()的区别.分享给大家供大家参考.具体分析如下: 一.Jquery中offset() 获取匹配元素在当前视口的相对偏移. 总是计算相对于文档的位置,无论元素的父元素或祖先元素的position属性是什么. 返回的对象包含两个整形属性:top 和 left.此方法只对可见元素有效.   例如: <!DOCTYPE html> <html> <head> <style> p { margin-left

js实现jquery的offset()方法实例_javascript技巧

本文实例讲述了js实现jquery的offset()方法.分享给大家供大家参考.具体分析如下: 用过jQuery的offset()的同学都知道offset().top或offset().left很方便地取得元素相对于整个页面的偏移. 而在js里,没有这样直接的方法,节点的属性offsetTop可以获得该节点相对于父节点的相对偏移,但不能直接获得其绝对偏移,我们可用节点逐层递归向上来相加offsetTop来获得绝对偏移. 复制代码 代码如下: function getOffset(Node, of