blog/_includes/extensions/geopattern.html
2019-09-11 12:21:17 +08:00

21 lines
556 B
HTML

{% if include.selector %}
{% assign selector = include.selector %}
{% endif %}
{% if include.seed %}
{% assign seed = include.seed %}
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
<script>
function setRandomBgImage(selector, seed) {
var pattern = GeoPattern.generate(seed);
var element = document.querySelector(selector)
if (element) {
element.style.backgroundImage = pattern.toDataUrl();
}
}
setRandomBgImage('{{ selector }}', '{{ seed }}');
</script>