1.如何获取、设置元素的宽度
2.如何通过fn设置元素的宽度
3.如何获取、设置元素的高度
4.如何通过fn设置元素的高度
5.如何获得元素的,包括内边距的高度,宽度
6.如何获得元素的,包含边框,内边框的宽度和高度
7.如何获取元素,包含边框,内边距,外边距的宽度和高度
8.如何获得某个元素对于可视窗口的位置的偏移量
9.如何获取某个元素相对于父亲元素的偏移量
10.如何获取、设置,垂直滚动条的值
//获取元素的宽度
/**
$(function(){
alert($('div').css('width'));//typeof是string
alert($('div').width());//typeof是number
})
*/
//设置元素的宽度
/**
$(function(){
//$('div').width(300);//直接传数字,默认单位是px
//$('div').width('500px');//传入带单位的字符串
$('div').width(function(index,value){
return value+100;
}) //直接修个宽度
})
*/
//高度设置和宽度设置一样
/**
$(function(){
alert('width'+':'+$('div').width());//文本的宽度
alert('inner'+':'+$('div').innerWidth());//文本宽度+padding的两倍
alert('outer'+':'+$('div').outerWidth(true));//文本宽度+padding两倍+margin两倍,括号内默认值是false,将不加margin值
})
*/
//获取偏移量
/**
$(function(){
//offset属性是object
alert('offset.left'+':'+$('div').offset().left);//获取距离左边的值
alert('offset.top'+':'+$('div').offset().top);//获取距离上面的值
alert('strong,offset.left'+':'+$('strong').offset().left);//获取子标签距离左边的值
alert('strong,offset.top'+':'+$('strong').offset().top);//获取子标签距离上面的值
alert('position.left'+':'+$('strong').position().left);//获取strong标签距离div标签左边的值
alert('position.top'+':'+$('strong').position().top);//获取strong标签距离div标签上面的值
})
*/
//获取滚动条的位置
/**
$(function(){
alert($(window).scrollTop());
})
*/
//通过滚动条定位页面
/**
$(function(){
$(window).scrollTop(90);
})
*/
2.如何通过fn设置元素的宽度
3.如何获取、设置元素的高度
4.如何通过fn设置元素的高度
5.如何获得元素的,包括内边距的高度,宽度
6.如何获得元素的,包含边框,内边框的宽度和高度
7.如何获取元素,包含边框,内边距,外边距的宽度和高度
8.如何获得某个元素对于可视窗口的位置的偏移量
9.如何获取某个元素相对于父亲元素的偏移量
10.如何获取、设置,垂直滚动条的值
//获取元素的宽度
/**
$(function(){
alert($('div').css('width'));//typeof是string
alert($('div').width());//typeof是number
})
*/
//设置元素的宽度
/**
$(function(){
//$('div').width(300);//直接传数字,默认单位是px
//$('div').width('500px');//传入带单位的字符串
$('div').width(function(index,value){
return value+100;
}) //直接修个宽度
})
*/
//高度设置和宽度设置一样
/**
$(function(){
alert('width'+':'+$('div').width());//文本的宽度
alert('inner'+':'+$('div').innerWidth());//文本宽度+padding的两倍
alert('outer'+':'+$('div').outerWidth(true));//文本宽度+padding两倍+margin两倍,括号内默认值是false,将不加margin值
})
*/
//获取偏移量
/**
$(function(){
//offset属性是object
alert('offset.left'+':'+$('div').offset().left);//获取距离左边的值
alert('offset.top'+':'+$('div').offset().top);//获取距离上面的值
alert('strong,offset.left'+':'+$('strong').offset().left);//获取子标签距离左边的值
alert('strong,offset.top'+':'+$('strong').offset().top);//获取子标签距离上面的值
alert('position.left'+':'+$('strong').position().left);//获取strong标签距离div标签左边的值
alert('position.top'+':'+$('strong').position().top);//获取strong标签距离div标签上面的值
})
*/
//获取滚动条的位置
/**
$(function(){
alert($(window).scrollTop());
})
*/
//通过滚动条定位页面
/**
$(function(){
$(window).scrollTop(90);
})
*/