blob: c11458e933a8dff16d0fafc129aae3f684ae9447 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
{% if include.selector %}
{% assign selector = include.selector %}
{% endif %}
{% if include.seed %}
{% assign seed = include.seed %}
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/trianglify/2.0.0/trianglify.min.js"></script>
<script>
function setRandomBgImage(selector, seed, zoom = 1) {
var element = document.querySelector(selector);
if (!element) return;
var pattern = Trianglify({
width: screen.width * zoom,
height: element.offsetHeight * zoom,
seed: seed
});
var image = document.createElement("div");
image.style.backgroundImage = "url(" + pattern.png() + ")";
element.appendChild(image);
}
setRandomBgImage('{{ selector }}', '{{ seed }}', {{ zoom | default: 1}});
</script>
|