Created
February 10, 2018 09:28
-
-
Save caseyWebb/01b78eccb10a7e6854a582f5d47180c2 to your computer and use it in GitHub Desktop.
SQIP Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.sqip-container { | |
position: relative; | |
} | |
.sqip-container .fq { | |
position: absolute; | |
top: 0; | |
z-index: 0; | |
} | |
.sqip { | |
position: relative; | |
z-index: 1; | |
transition: opacity .25s ease-in-out; | |
} | |
.sqip.hidden { | |
opacity: 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="sqip-container"> | |
<img class="sqip" src="{{@blog.cover_image}}.sqip.svg" /> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelectorAll('img.sqip').forEach(transitionFullQuality) | |
function transitionFullQuality($sqip) { | |
const $fq = document.createElement('img') | |
$fq.classList.add('fq') | |
$fq.setAttribute('src', $sqip.getAttribute('src').replace('.sqip.svg', '')) | |
$sqip.insertAdjacentElement('afterend', $fq) | |
const onLoad = () => setTimeout(() => $sqip.classList.add('hidden'), 500) | |
if ($fq.complete) { | |
onLoad() | |
} else { | |
$fq.addEventListener('load', onLoad) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment