Я работаю над мозаичным макетом, в котором я хочу, чтобы плитки случайным образом увеличивались в два раза. Это отлично работает в браузере типа Chromium, но не в Firefox.
В большинстве браузеров работает следующее:
scale: 2;
Что не работает в Firefox:
:root {
--tile-count-width: 3;
--tile-count-height: 3;
--tile-gap: 12px;
--tile-size:
calc((100vw - (var(--tile-count-width) + 1) * var(--tile-gap)) / var(--tile-count-width));
}
scale: calc((var(--tile-size) * 2 + var(--tile-gap)) / var(--tile-size));
Причина расчета заключается в том, что Calc(2) не учитывает размер пробела в сетке.
Полный код:
1
2
3
4
5
6
container {
--tile-count-width: 3;
--tile-count-height: 3;
--tile-gap: 12px;
--tile-size:
calc((100vw - (var(--tile-count-width) + 1) * var(--tile-gap)) / var(--tile-count-width));
max-width: fit-content;
margin: auto;
display: grid;
gap: var(--tile-gap);
grid-template:
repeat(var(--tile-count-height), var(--tile-size)) / repeat(var(--tile-count-width), var(--tile-size));
}
container>div {
position: relative;
}
container>div .inner {
position: absolute;
top: 0;
left: 0;
width: var(--tile-size);
height: var(--tile-size);
background-color: yellow;
transform-origin: top left;
transition: scale 0ms ease-in-out;
}
container>div[large] {
grid-column: span 2;
grid-row: span 2;
}
container>div[large] .inner {
transition: scale 1s ease-in-out;
scale: calc((var(--tile-size) * 2 + var(--tile-gap)) / var(--tile-size));
}
const container = document.querySelector('container');
const gridTemplate = getComputedStyle(container).gridTemplate;
const columnPart = gridTemplate.split('/')[1].trim();
const columnRepeatValue = parseInt(columnPart.match(/\d+/)[0]);
const tiles = document.querySelectorAll("container>div");
let sourceIndex = 0;
let currentIndex = 0;
const interval = setInterval(() => {
let i;
do {
i = Math.floor(Math.random() * (tiles.length-(columnRepeatValue-2)));
} while(i==sourceIndex || (i + 1) % columnRepeatValue === 0);
const sourceTile = tiles[sourceIndex];
const targetTile = tiles;
if (sourceTile && targetTile) {
const largeValue = sourceTile.getAttribute("large");
if (largeValue !== null) {
sourceTile.removeAttribute("large");
targetTile.setAttribute("large", largeValue);
sourceIndex = i;
}
}
currentIndex++;
}, 3000); // 1 second delay between each iteration
Подробнее здесь: https://stackoverflow.com/questions/798 ... in-firefox
Функция масштабирования в Firefox ⇐ CSS
Разбираемся в CSS
1763622651
Anonymous
Я работаю над мозаичным макетом, в котором я хочу, чтобы плитки случайным образом увеличивались в два раза. Это отлично работает в браузере типа Chromium, но не в Firefox.
В большинстве браузеров работает следующее:
scale: 2;
Что не работает в Firefox:
:root {
--tile-count-width: 3;
--tile-count-height: 3;
--tile-gap: 12px;
--tile-size:
calc((100vw - (var(--tile-count-width) + 1) * var(--tile-gap)) / var(--tile-count-width));
}
scale: calc((var(--tile-size) * 2 + var(--tile-gap)) / var(--tile-size));
Причина расчета заключается в том, что Calc(2) не учитывает размер пробела в сетке.
Полный код:
1
2
3
4
5
6
container {
--tile-count-width: 3;
--tile-count-height: 3;
--tile-gap: 12px;
--tile-size:
calc((100vw - (var(--tile-count-width) + 1) * var(--tile-gap)) / var(--tile-count-width));
max-width: fit-content;
margin: auto;
display: grid;
gap: var(--tile-gap);
grid-template:
repeat(var(--tile-count-height), var(--tile-size)) / repeat(var(--tile-count-width), var(--tile-size));
}
container>div {
position: relative;
}
container>div .inner {
position: absolute;
top: 0;
left: 0;
width: var(--tile-size);
height: var(--tile-size);
background-color: yellow;
transform-origin: top left;
transition: scale 0ms ease-in-out;
}
container>div[large] {
grid-column: span 2;
grid-row: span 2;
}
container>div[large] .inner {
transition: scale 1s ease-in-out;
scale: calc((var(--tile-size) * 2 + var(--tile-gap)) / var(--tile-size));
}
const container = document.querySelector('container');
const gridTemplate = getComputedStyle(container).gridTemplate;
const columnPart = gridTemplate.split('/')[1].trim();
const columnRepeatValue = parseInt(columnPart.match(/\d+/)[0]);
const tiles = document.querySelectorAll("container>div");
let sourceIndex = 0;
let currentIndex = 0;
const interval = setInterval(() => {
let i;
do {
i = Math.floor(Math.random() * (tiles.length-(columnRepeatValue-2)));
} while(i==sourceIndex || (i + 1) % columnRepeatValue === 0);
const sourceTile = tiles[sourceIndex];
const targetTile = tiles[i];
if (sourceTile && targetTile) {
const largeValue = sourceTile.getAttribute("large");
if (largeValue !== null) {
sourceTile.removeAttribute("large");
targetTile.setAttribute("large", largeValue);
sourceIndex = i;
}
}
currentIndex++;
}, 3000); // 1 second delay between each iteration
Подробнее здесь: [url]https://stackoverflow.com/questions/79824763/scale-function-in-firefox[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия