【发布时间】:2011-11-26 07:44:51
【问题描述】:
我有一些代码可以为我提供一个保持原始比例的全屏图像(即横向完全拉伸宽度方式和纵向高度方式)。我需要能够在页面周围有不同的边框(即顶部:100,左和右:120,底部:200),图像将停止并且不会侵入。我有什么简单的解决方法吗?
感谢任何帮助!
function FullScreenBackground(theItem,imageWidth,imageHeight){
var winWidth=$(window).width();
var winHeight=$(window).height();
var picHeight = imageHeight / imageWidth;
var picWidth = imageWidth / imageHeight;
if ((winHeight / winWidth) > picHeight) {
$(theItem).attr("width",winWidth);
$(theItem).attr("height",picHeight*winWidth);
} else {
$(theItem).attr("height",winHeight);
$(theItem).attr("width",picWidth*winHeight);
};
$(theItem).css("margin-left",(winWidth-$(theItem).width())/2);
$(theItem).css("margin-top",(winHeight-$(theItem).height())/2);
}
亲爱的主......请有人帮助我!
Swatkins 的回答确实给了我边框,但图像没有按约束比例缩放。
我正在使用 Malihu 的这个很棒的插件: http://manos.malihu.gr/simple-jquery-fullscreen-image-gallery
但正如我上面所说的那样,只是试图在图像周围设置不同的边框。
任何帮助都会很棒
【问题讨论】:
标签: jquery image window fullscreen