我必须用每种屏幕分辨率来适应屏幕上的所有图像。
我应该使用$(window)还是$(document)来测量height /width以自动适应图像。
发布于 2012-07-31 14:28:43
如果所有图像的高度都不固定,则使用
$(window).load(function () {
// your code goes here which will be executed once all the images
// got loaded (seen)
});如果要加载的所有图像的高度都是固定的,那么不要等待图像加载,只需为<img>标签分配固定的高度并对其进行拟合即可。使用
$(document).ready(function () {
// your code goes here which will be executed once the DOM is ready
// (means all the tags including IMG tags) are loaded.
});发布于 2012-07-31 14:26:03
您需要获取$(窗口)。
window包括document。window是浏览器屏幕,所以屏幕上的可视区域,而document是您的文档。所以加载到浏览器中的html页面,可以比屏幕尺寸小。
发布于 2012-07-31 14:29:02
我像这样使用window:
function resizeThings(){
var winH = $(window).height();
var winW = $(window).width();
// let's say you are trying to match images to height
$('img').each(function(){
$(this).css('height', winH);
}); };
https://stackoverflow.com/questions/11734293
复制相似问题