2019-06-17

尺寸相关、滚动事件

1、获取和设置元素的尺寸

width()、height()    获取元素width和height 

innerWidth()、innerHeight()  包括padding的width和height 

outerWidth()、outerHeight()  包括padding和border的width和height 

outerWidth(true)、outerHeight(true)   包括padding和border以及margin的width和height

2、获取元素相对页面的绝对位置

offset()

3、获取可视区高度 

$(window).height();

4、获取页面高度 

$(document).height();

5、获取页面滚动距离

$(document).scrollTop(); 

$(document).scrollLeft();

6、页面滚动事件 

$(window).scroll(function(){ 

    ...... 

})

元素绝对位置

$(function(){

var $pos = $('.pos');

//offset().log(pos);

// alert(pos.left + "," + pos.top);

var w = $pos.ou是获取相对于页面左上角的绝对位置,即使外面再包一层con居中层,也不影响效果

var pos = $pos.offset();

// consoleterWidth();

var h = $pos.outerHeight();

// alert(w);

$('.pop').css({left:pos.left + w,top:pos.top});

$pos.mouseover(function() {

$('.pop').show();

});

$pos.mouseout(function() {

$('.pop').hide();

});

})


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容