如何在JavaScript或HTML中调整动画gif的大小
我需要在SplashScreen上为Android显示一个动画。我想根据屏幕的高度和宽度调整它的大小。我可以通过使用webView和javascript成功地将其应用于屏幕。但我无法调整它的大小: 我写我的代码,也许有人会需要它 这是index.html中的html代码,我可以用Java编写,但我不能用它显示动画gif如何在JavaScript或HTML中调整动画gif的大小,javascript,android,html,animated-gif,Javascript,Android,Html,Animated Gif,我需要在SplashScreen上为Android显示一个动画。我想根据屏幕的高度和宽度调整它的大小。我可以通过使用webView和javascript成功地将其应用于屏幕。但我无法调整它的大小: 我写我的代码,也许有人会需要它 这是index.html中的html代码,我可以用Java编写,但我不能用它显示动画gif <html> <head> <title></title> </head> <body style="paddi
<html>
<head>
<title></title>
</head>
<body style="padding: 0; margin: 0">
<script type="text/javascript">
function resize(image)
{
var differenceHeight = document.body.clientHeight - image.clientHeight;
var differenceWidth = document.body.clientWidth - image.clientWidth;
if (differenceHeight < 0) differenceHeight = differenceHeight * -1;
if (differenceWidth < 0) differenceWidth = differenceWidth * -1;
if (differenceHeight > differenceWidth)
{
image.style['height'] = document.body.clientHeight + 'px';
}
else
{
image.style['width'] = document.body.clientWidth + 'px';
}
// Optional: remove margins or compensate for offset.
image.style['margin'] = 0;
document.body.style['margin'] = 0;
}
</script>
<img src="file:///android_asset/html/screen1.gif"
onload="resize(this);"/>
</body>
</html>
您需要比较图像的高宽比与显示器的高宽比
var imageRatio = image.clientHeight / image.clientWidth;
var clientRatio = document.body.clientHeight / document.body.clientWidth;
if (imageRatio > clientRatio)
{
image.style['height'] = document.body.clientHeight + 'px';
}
else
{
image.style['width'] = document.body.clientWidth + 'px';
}
我对什么不起作用感到困惑。这似乎是它应该做你想要的…宽度是可以的,但动画的高度比屏幕的长我认为;您比较了比率,但没有为此比率调整图像大小。我需要调整图像与屏幕的比例?我在这里尝试过:这是你想要的功能吗?您可以调整结果框的大小,以模拟设备的不同宽度和高度。我的设备屏幕为480x800像素。但是我在网络视图上看不到这个像素?webView是全屏的。为什么我们不能设置高度和宽度,当我设置两个值时,图像比屏幕大。。。我提醒你,我的图像是动画gif
var imageRatio = image.clientHeight / image.clientWidth;
var clientRatio = document.body.clientHeight / document.body.clientWidth;
if (imageRatio > clientRatio)
{
image.style['height'] = document.body.clientHeight + 'px';
}
else
{
image.style['width'] = document.body.clientWidth + 'px';
}