我有以下代码是以浏览器窗口的高基准。
我的问题是我是否只能跑到正面的正面宽度宽度(例如Div#Container 980px)。
$(window).resize(function(){
var ventana = $(window).height();
var altura = ventana / 2;
$("#gallery").css('height', altura);
});
问候
使用 if( $( window ).width() > x )
仅启用特定窗口宽度的调整效果:
var window = $( window );
window.resize( function() {
if( window.width() > 980 )
{
var ventana = window.height();
$( '#gallery' ).css( 'height', ventana / 2 );
}
else
{
/* reset for browsers that fire the event only once
* at the end of the window resize action */
$( '#gallery' ).css( 'height', 'auto' );
}
} );
当然,您在此行要求浏览器窗口的高度
var ventana = $(window).height();
将其更改为
var ventana = $("#container").height();
获得您网站的高度。但是您可能需要宽度,因此您应该致电width()
。如果您要问的是您的实际网站大小时仅运行代码(我不会说西班牙语,但我认为我理解您的问题),则使用:
$("#container").resize(function(){
//code
});
当然,当您设置固定宽度时,这将行不通。