我想尝试创建一个类似于信使的应用程序,但我看到一篇文章说你需要将所有信件转交给当局。我在互联网上几乎找不到任何其他相关信息,所以我在这里询问。
因此,我有一个标题屏幕“动画”,其中标题标题位于全屏页面的中心,当我向下滚动时,它会变小并停留在页面顶部。这是一个具有预期行为的工作示例,我从中删除了所有不必要的代码以保持最少:
$(window).scroll( () => {
"use strict";
let windowH = $(window).height();
let windowS = $(window).scrollTop();
let header = $("#header").height();
if (windowS < windowH-header) {
$("#title").css("transform", "scale("+(2-(windowS/($(document).outerHeight()-windowH))*2.7)+")");
$("#header").css("transform", "translateY(0)");
$("#inside, #content").css({
"position": "static",
"margin-top": 0
});
} else {
$("#inside").css({
"position": "fixed",
"margin-top": -windowH+header
});
$("#content").css("margin-top", windowH);
}
$("#header").css("position", windowS > (windowH-header)/2 ? "fixed" :"static");
});
.fixed {
position: fixed!important;
}
.wrapper {
width: 100%;
text-align: center;
}
.wrapper:before {
display: table;
content: " ";
}
.wrapper:after {
clear: both;
}
#inside {
width: 100%;
height: 100vh;
background-color: lightcoral;
display: flex;
align-items: center;
justify-content: center;
}
#header {
height: 90px;
top: 0;
position: sticky;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.5s;
}
#title {
width: 100%;
color: #fff;
transform: scale(2);
}
#content {
height: 1000px;
background-color: lightblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="wrapper">
<div id="inside">
<div id="header">
<h1 id="title">Title</h1>
</div>
</div>
<div id="content"></div>
</body>
接下来是相同的片段,但添加了一个:我应用了一个过滤器,在我看来,这纯粹是装饰性的:filter: Brightness(1.3);。
正如您在下面看到的,当您滚动“动画”一半时,标题就会消失。当您检查该元素时,它仍然保留其所有属性,但不知何故它不在那里。同样的事情发生在 Firefox 和 Chrome 中,我不知道为什么。
如果有人能发布一个应用了过滤器的工作片段并解释为什么它之前不起作用,我将非常感激。
$(window).scroll( () => {
"use strict";
let windowH = $(window).height();
let windowS = $(window).scrollTop();
let header = $("#header").height();
if (windowS < windowH-header) {
$("#title").css("transform", "scale("+(2-(windowS/($(document).outerHeight()-windowH))*2.7)+")");
$("#header").css("transform", "translateY(0)");
$("#inside, #content").css({
"position": "static",
"margin-top": 0
});
} else {
$("#inside").css({
"position": "fixed",
"margin-top": -windowH+header
});
$("#content").css("margin-top", windowH);
}
$("#header").css("position", windowS > (windowH-header)/2 ? "fixed" :"static");
});
.fixed {
position: fixed!important;
}
.wrapper {
width: 100%;
text-align: center;
}
.wrapper:before {
display: table;
content: " ";
}
.wrapper:after {
clear: both;
}
#inside {
width: 100%;
height: 100vh;
background-color: lightcoral;
filter: brightness(1.3); /*<<<<<<<<<<<<<<<<*/
display: flex;
align-items: center;
justify-content: center;
}
#header {
height: 90px;
top: 0;
position: sticky;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.5s;
}
#title {
width: 100%;
color: #fff;
transform: scale(2);
}
#content {
height: 1000px;
background-color: lightblue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="wrapper">
<div id="inside">
<div id="header">
<h1 id="title">Title</h1>
</div>
</div>
<div id="content"></div>
</body>
问题的免费翻译为什么将 CSS 过滤器应用于父元素会破坏子元素的定位?来自成员 @leonheess。
我曾经认为当我们创建像这样的多维数组时
int arr[2][3] =
{
{1, 2, 3},
{1, 2, 3}
}
内存中分配了两个单元,每个单元都占用sizeof(int) * 3,因此您可以轻松访问任何元素。例如,当访问最后三个时arr[1][2],在指针级别它将如下所示*(arr + (sizeof(int) * 3 * 1) + 2)。嗯,这样的数组正好占用 2x3 内存。
但后来我在指针层面看到了这样的公式arr[1][2] => *(*(arr + 1) + 2),得出的结论是,多维数组在内存中存储如下(这里我将这样表示内存0[5],其中0是单元格地址[5], 是存储在单元格内部的值): 0[адрес 2], 1[адрес 5], 2[1], 3[2], 4[3], 5[1], 6[2], 7[3]. 通过这样的存储,您可以轻松理解为什么*(*(*(arr + i) + j) + k)在每个级别的该公式中都会发生取消引用。然而,采用这种存储方式,同一个数组已经占用了2+2x3。
既然存储的是多维数组,如果我描述的第二种方法是正确的,那么它比第一种方法有什么优势呢?