Last active
September 12, 2017 20:00
-
-
Save techanon/7aef0bb122d4ac4e34cd1a785ce66bdd to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
/* demo purpose only */ | |
body {display:flex; } | |
/** CSS **/ | |
.blurbox { | |
--size: 500px; | |
display: grid; | |
width:var(--size); | |
height:var(--size); | |
position:relative; | |
overflow:hidden; | |
} | |
.blurbox img { | |
width: 100%; | |
height: 100%; | |
opacity: 0; | |
z-index:1; | |
position:relative; | |
} | |
.blurbox::before, .blurbox::after { | |
content:""; | |
background-image: var(--img); | |
background-repeat: no-repeat; | |
background-position: center center; | |
width: 100%; | |
height: 100%; | |
position: absolute; | |
} | |
.blurbox::before { | |
z-index:-1; | |
filter:blur(5px); | |
background-size: cover; | |
} | |
.blurbox::after { | |
z-index:0; | |
background-size: contain; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- pseudo template-like | |
<div class="blurbox" style="--img:url( {{ data.imgurl }} );"><img src="{{ data.imgurl }}"></div> | |
--> | |
<div class="blurbox" style="--img:url(http://i.imgur.com/pIUsuyE.jpg);"><img src="http://i.imgur.com/pIUsuyE.jpg"></div> | |
<div class="blurbox" style="--img:url(http://i.imgur.com/WPsf4eg.jpg);"><img src="http://i.imgur.com/WPsf4eg.jpg"></div> | |
<!-- script to update image --> | |
<script> | |
function switchImg(e){ | |
let el = e.currentTarget; | |
let img = "/path/to/img.jpg"; | |
el.style = "--img:url("+img+")"; | |
el.firstChild.src = img; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment