我的数字范围是<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 20%;
left: 20%;
transform: translate(-20%, -20%);
-ms-transform: translate(-20%, -20%);
text-align: center;
}
</style>
</head>
<body>
<h2>Fade in Overlay</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="https://s4827.pcdn.co/wp-content/uploads/2016/03/stack_overflow_logo.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</div>
</div>
</div>
</body>
</html>
至-100
。
我正在尝试将其标准化为100
到0
并保留小数位数。
3
我想创建一个程序函数以将任何范围标准化为任何值,例如:
http://rextester.com/ZJWNS24313
-100 = 0
-50 = 0.75
0 = 1.5
50 = 2.25
100 = 3
但是这不能提供正确的输出。
double Normalize(double val, double valmin, double min, double max)
{
return (val - valmin) / (max - min);
}
变为100
,而不是66.6666666666667
。
如果我将公式乘以十进制3
,结果将是正确的。
0.045
= ((100 - -100) / (3 - 0)) * 0.045
3
= ((50 - -100) / (3 - 0)) * 0.045
2.25
= ((-50 - -100) / (3 - 0)) * 0.045
但是如何制作公式,这样我不必在末尾指定十进制数字?
因为如果我想将新数字从0.75
标准化为0
,则必须将其更改为5
。
答案 0 :(得分:2)
尝试一下:
double Normalize(double val, double valmin, double valmax, double min, double max)
{
return (((val - valmin) / (valmax - valmin)) * (max - min)) + min;
}
(假设valmin和valmax为-100至100,min和max为0至3)
编辑:应在末尾加上最小值而不是减去