嘿伙计们,我试图缩放不同尺寸的不同图像(例如:900:600,750:400)。
我的目标:如果高度大于设备高度,请缩放图像宽度。如果我使用ipad并将方向更改为纵向,我的图像将采用全宽,但这会导致设备的高度更高。
有没有办法按固定高度缩放图像并确定比例宽度?
我尝试了什么:
我正在考虑设置图像高度并获得一个由其高度决定的新宽度:
function ScaleSlider() {
var ori = window.orientation;
var screenwidth = (ori==90 || ori==-90) ? screen.height : screen.width;
var screenheight = (ori==90 || ori==-90) ? screen.width : screen.height;
var refHeight = slider.$Elmt.parentNode.clientHeight;
var refWidth = slider.$Elmt.parentNode.clientWidth;
console.log(screenwidth);
console.log(screenheight);
if (screenwidth) {
if(refHeight > screenheight){
refHeight = screenheight;
slider.$ScaleHeight(refHeight);
}else if(refWidth > screenwidth){
var refWidth = screenwidth;
slider.$ScaleWidth(screenwidth);
}
}
else {
window.setTimeout(ScaleSlider, 1);
}
}
ScaleSlider();
$Jssor$.$AddEvent(window, "load", ScaleSlider);
$Jssor$.$AddEvent(window, "resize", $Jssor$.$WindowResizeFilter(window, ScaleSlider));
$Jssor$.$AddEvent(window, "orientationchange", ScaleSlider);
注意
新版本:
function ScaleSlider() {
var refSize = slider.$Elmt.parentNode.clientWidth;
var refHeight = slider.$Elmt.parentNode.clientHeight;
var deviceHeight = (window.innerHeight > 0) ? window.innerHeight : screen.height;
console.log(deviceHeight);
if(refHeight > deviceHeight){
slider.$ScaleHeight(deviceHeight);
console.log(refHeight);
}else{
slider.$ScaleWidth(refSize);
}
}