jQuery - ³ß´ç
ͨ¹ý jQuery£¬ºÜÈÝÒ×´¦ÀíÔªËØºÍä¯ÀÀÆ÷´°¿ÚµÄ³ß´ç¡£
jQuery ³ß´ç ·½·¨
jQuery Ìṩ¶à¸ö´¦Àí³ß´çµÄÖØÒª·½·¨£º
- width()
- height()
- innerWidth()
- innerHeight()
- outerWidth()
- outerHeight()
jQuery width() ºÍ height() ·½·¨
width() ·½·¨ÉèÖûò·µ»ØÔªËصĿí¶È£¨²»°üÀ¨Äڱ߾ࡢ±ß¿ò»òÍâ±ß¾à£©¡£
height() ·½·¨ÉèÖûò·µ»ØÔªËصĸ߶ȣ¨²»°üÀ¨Äڱ߾ࡢ±ß¿ò»òÍâ±ß¾à£©¡£
ÏÂÃæµÄÀý×Ó·µ»ØÖ¸¶¨µÄ <div> ÔªËØµÄ¿í¶ÈºÍ¸ß¶È£º
ʵÀý
$("button").click(function(){
var txt="";
txt+="Width: " + $("#div1").width() + "</br>";
txt+="Height: " + $("#div1").height();
$("#div1").html(txt);
});
jQuery innerWidth() ºÍ innerHeight() ·½·¨
innerWidth() ·½·¨·µ»ØÔªËصĿí¶È£¨°üÀ¨Äڱ߾ࣩ¡£
innerHeight() ·½·¨·µ»ØÔªËصĸ߶ȣ¨°üÀ¨Äڱ߾ࣩ¡£
ÏÂÃæµÄÀý×Ó·µ»ØÖ¸¶¨µÄ <div> ÔªËØµÄ inner-width/height£º
ʵÀý
$("button").click(function(){
var txt="";
txt+="Inner width: " + $("#div1").innerWidth() + "</br>";
txt+="Inner height: " + $("#div1").innerHeight();
$("#div1").html(txt);
});
jQuery outerWidth() ºÍ outerHeight() ·½·¨
outerWidth() ·½·¨·µ»ØÔªËصĿí¶È£¨°üÀ¨Äڱ߾àºÍ±ß¿ò£©¡£
outerHeight() ·½·¨·µ»ØÔªËصĸ߶ȣ¨°üÀ¨Äڱ߾àºÍ±ß¿ò£©¡£
ÏÂÃæµÄÀý×Ó·µ»ØÖ¸¶¨µÄ <div> ÔªËØµÄ outer-width/height£º
ʵÀý
$("button").click(function(){
var txt="";
txt+="Outer width: " + $("#div1").outerWidth() + "</br>";
txt+="Outer height: " + $("#div1").outerHeight();
$("#div1").html(txt);
});
outerWidth(true) ·½·¨·µ»ØÔªËصĿí¶È£¨°üÀ¨Äڱ߾ࡢ±ß¿òºÍÍâ±ß¾à£©¡£
outerHeight(true) ·½·¨·µ»ØÔªËصĸ߶ȣ¨°üÀ¨Äڱ߾ࡢ±ß¿òºÍÍâ±ß¾à£©¡£
ʵÀý
$("button").click(function(){
var txt="";
txt+="Outer width (+margin): " + $("#div1").outerWidth(true) + "</br>";
txt+="Outer height (+margin): " + $("#div1").outerHeight(true);
$("#div1").html(txt);
});
jQuery - ¸ü¶àµÄ width() ºÍ height()
ÏÂÃæµÄÀý×Ó·µ»ØÎĵµ£¨HTML Îĵµ£©ºÍ´°¿Ú£¨ä¯ÀÀÆ÷ÊÓ¿Ú£©µÄ¿í¶ÈºÍ¸ß¶È£º
ʵÀý
$("button").click(function(){
var txt="";
txt+="Document width/height: " + $(document).width();
txt+="x" + $(document).height() + "\n";
txt+="Window width/height: " + $(window).width();
txt+="x" + $(window).height();
alert(txt);
});
ÏÂÃæµÄÀý×ÓÉèÖÃÖ¸¶¨µÄ <div> ÔªËØµÄ¿í¶ÈºÍ¸ß¶È£º
ʵÀý
$("button").click(function(){
$("#div1").width(500).height(500);
});
jQuery CSS ²Î¿¼ÊÖ²á
ÈçÐè¹ØÓÚ jQuery Dimensions µÄÍêÕû²Î¿¼£¬Çë·ÃÎÊÎÒÃÇµÄ jQuery ³ß´ç²Î¿¼Êֲᡣ