Skip to content

Instantly share code, notes, and snippets.

@stasgavrylov
Created December 8, 2015 11:48
Show Gist options
  • Save stasgavrylov/61c2b1e833a0ba30b278 to your computer and use it in GitHub Desktop.
Save stasgavrylov/61c2b1e833a0ba30b278 to your computer and use it in GitHub Desktop.
Blur on resize
// Adjust blur on resize.
var proto = Object.create(HTMLElement.prototype);
proto.attachedCallback = function()
{
var feGaussianBlur = this.query('feGaussianBlur')
var MAX_DEVIATION = 10
var MIN_DEVIATION = 3
var MIN_WIDTH = 320
var MAX_WIDTH = 1366
var k = (MAX_WIDTH - MIN_WIDTH) / (MAX_DEVIATION - MIN_DEVIATION)
function calculateDeviation()
{
var width = global.innerWidth
if (width > MAX_WIDTH) return MIN_DEVIATION
else
{
var diff = width - MIN_WIDTH
return MAX_DEVIATION - diff / k
}
}
function setDeviation(deviation)
{
feGaussianBlur.setStdDeviation(deviation, deviation)
}
function updateDeviation() {
var deviation = calculateDeviation()
setDeviation(deviation)
}
on(window, 'resize', updateDeviation)
updateDeviation()
};
var platformBlur = document.registerElement('platform-blur',
{
prototype: proto
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment