如何除錯 CSS calc() 值?
問題
我有相對複雜的公式,例如:transform: scale(var(--image-scale)) translateY(calc ((1px var(--element-height) (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y)))
如何調試計算出的值?
此外,是否有辦法驗證/突出顯示公式錯誤?
我試試看
position: fixed;<pre class="brush:php;toolbar:false">display: block; left:0; right: 0; background: yellow; padding: 5px; z-index: 100; content: calc((1px * var(--element-height) * (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y));
沒有用
我發現的唯一方法是將計算的一部分放在未使用的數字屬性中,例如,下面的gif 中的background-position-x,這樣它將在計算選項卡上顯示計算的值——有用但不太方便(notice background-position-x 在頁面滾動時發生變化):
<pre class="brush:php;toolbar:false">cssProps: true
})
const results = Splitting();
var parallaxedElements = document.querySelectorAll('.section');
document.addEventListener('scroll', function(e) {
parallaxedElements Array.from(parallaxedElements).forEach((el) => { var bcr = el.getBoundingClientRect(); if (bcr.y < 0 && Math.abs(bcr.y) <= bcr.height) { el.style.setProperty("--scrolled-out-y", Math.round(Math.abs(bcr.y) * 10000 / bcr.height) / 10000); } });
})
html {<pre class="brush:php;toolbar:false">scroll-behavior: smooth;
}
body {
font-family: "Roboto"; font-size: 14px; line-height: 1.4; scroll-behavior: smooth;
}
.section {
position: relative; background-attachment: fixed; z-index: 1; --image-scale: 1.2; --scrolled-out-y: 0;
}
.section__background {
}position: -webkit-sticky; position: sticky; top: 0; width: 100%; height: 100vh; overflow: hidden;
.section__background {
}content: ""; position: absolute; bottom: 0; left: 0; right: 0; top: 0; z-index: 1; background: linear-gradient(to bottom, black, 100% white); background: rgba(0, 0, 0, 0.4); opacity: calc(1 + ((var(--viewport-y) * 1.5)));
.section__background:after {
}height: 150vh; width: 100%; object-fit: cover; position: absolute; left: 0; top: 0px; user-select: none; transform: scale(var(--image-scale)) translateY(calc((-1px * var(--element-height) * (var(--image-scale) - 1)) * var(--scrolled-out-y)));
.section__background>img {
position: fixed; display: block; left: 0; right: 0; background: pink; padding: 5px; z-index: 100; content: calc((1px * var(--element-height) * (var(--image-scale) - 1)) / 2 * var(--scrolled-out-y)); } */
/* .indicator:after {
padding-bottom: 50vh; overflow: hidden; align-items: flex-start; position: relative; z-index: 4;
}
color: #fff; text-transform: uppercase; font-size: 45px; line-height: 1.2; font-weight: 800; letter-spacing: 8px; margin: 0; overflow: hidden; position: relative; padding-bottom: 50px; margin-bottom: 50px;
}
content: ""; position: absolute; top: 200px; left: 0; right: 0; height: 2px; transform: translateX(calc(var(--scrolled-out-y) * 100% - 70%)); background: #b38c6b;
}
.section__heading:after {
}display: flex; color: white; flex-direction: column;
.section__content {
}margin-top: 20px;
.section__content p p {
}--char-percent: calc(var(--char-index) / var(--char-total));
.splitting {
.splitting .char {
display: inline-block; opacity: calc(1 + ((var(--viewport-y) * 1.5) - var(--char-percent)));
}
<link rel="stylesheet" href="https://unpkg.com/splitting/dist/splitting.css"><p><section data-scroll> <div class="section__background"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><div>
<div>
以上是如何調試 CSS `calc()` 值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!