Skip to content

Commit

Permalink
Merge pull request #15 from justbetter/feature/blurry-fix
Browse files Browse the repository at this point in the history
Use borderBoxSize on safari and load images lazy by default
  • Loading branch information
BobWez98 authored Dec 11, 2024
2 parents 911703c + 5d65d8e commit 4a38144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 2 additions & 7 deletions resources/views/image.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ class="{{ $class }}"
<img
{!! $attributes ?? '' !!}
class="{{ $class }}"
@if($presets['placeholder'] ?? false)
style="background-image: url('{{ $presets['placeholder'] }}'); background-size: contain; background-position: center; background-repeat: no-repeat;"
@endif
src="{{ $presets['placeholder'] ?? $image->url() }}"
alt="{{ $alt ?? $image->alt() }}"
width="{{ $width }}"
height="{{ $height }}"
loading="lazy"
onload="
this.onload=()=>{
this.style.backgroundImage = null;
this.onload=null
};
this.onload = null;
window.responsiveResizeObserver.observe(this);
"
>
Expand Down
5 changes: 2 additions & 3 deletions resources/views/partials/head.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script>
window.responsiveResizeObserver = new ResizeObserver(async (entries) => {
entries.forEach(entry => {
let imgWidth = entry?.devicePixelContentBoxSize?.[0]?.inlineSize || 0;
let imgWidth = entry?.devicePixelContentBoxSize?.[0]?.inlineSize || (entry.borderBoxSize[0]?.inlineSize * window.devicePixelRatio);
if (imgWidth === 0) {
return;
}
requestAnimationFrame(() => {
entry.target.loading = 'lazy';
entry.target.parentNode.querySelectorAll('source').forEach((source) => {
source.sizes = imgWidth + 'px'
})
Expand Down

0 comments on commit 4a38144

Please sign in to comment.