Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据计数和固定包装器调整和计算元素大小_Javascript_Jquery - Fatal编程技术网

Javascript 根据计数和固定包装器调整和计算元素大小

Javascript 根据计数和固定包装器调整和计算元素大小,javascript,jquery,Javascript,Jquery,假设您有一个大小为100px X 100px的块(div) 现在我把一张大小为100x100px的图像传递到这个块中。尺寸一样,所以很合身 现在的问题是:如果我有2个、3个或6个图像,并且希望它们显示在100x100px的框中,那么最好的方法是什么 示例:1张图像->100*100,2张图像各50*50,9张图像各33%*33% 图像将始终具有相同的宽度和高度 谢谢你的小费 你回答了自己的问题:-) imageWidth=containerWidth/amountImages 对于您的“瓷砖”解

假设您有一个大小为100px X 100px的块(div)

现在我把一张大小为100x100px的图像传递到这个块中。尺寸一样,所以很合身

现在的问题是:如果我有2个、3个或6个图像,并且希望它们显示在100x100px的框中,那么最好的方法是什么

示例:1张图像->100*100,2张图像各50*50,9张图像各33%*33%

图像将始终具有相同的宽度和高度


谢谢你的小费

你回答了自己的问题:-)

imageWidth=containerWidth/amountImages

对于您的“瓷砖”解决方案,您可以

imageWidth=containerWidth/amountImagesInRow

imageHeight=containerHeight/amountimagesin列

如果要确定需要多少行/列: 定义最小宽度并执行某种操作

(…){

如果imageWidth

amountimage-=1;

imageWidth=containerWidth/amountImages

}


imagesInRow=amountImages

另外,imageHeight=containerHeight/amountImages.eh抱歉,伙计们,那么,对于9张图像,30%X 30%的效果如何???用你的解决方案,大概是11.11%。我不会问是否会这么容易:)嗨,卢克,还是那么容易:-)你想要的是一些瓷砖。您可以将宽度公式化为imageWidth=containerWidth/AmountImagesRow imageHeight=containerHeight/AmountImagesCol