├── README.md ├── blureffect.js ├── images ├── autumn-blur.jpg └── autumn.jpg ├── index.html └── style.css /README.md: -------------------------------------------------------------------------------- 1 | # Blur-effec-on-scroll 2 | 3 | 4 | スクロールすると背景画像がボケていくMedium風のエフェクト。 5 | 6 | [DEMO](http://codepen.io/harayu/pen/VvNKJB) (Codepen) 7 | 8 | ![fig](https://dl.dropboxusercontent.com/u/587895/github/blureffect.gif) 9 | -------------------------------------------------------------------------------- /blureffect.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'user strict'; 3 | var hello = document.getElementById('hello'), 4 | blur = document.getElementById('overlay'), 5 | windowHeight = window.innerHeight, 6 | isScroll = false; 7 | 8 | var latestScroll = 0; 9 | var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || 10 | window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; 11 | 12 | window.requestAnimationFrame = requestAnimationFrame; 13 | 14 | var init = function() { 15 | window.addEventListener('scroll', function(){ 16 | latestScroll = window.scrollY; 17 | checkScroll(); 18 | }, false); 19 | } 20 | 21 | var checkScroll = function() { 22 | if(!isScroll) { 23 | window.requestAnimationFrame(update); 24 | } 25 | isScroll = true; 26 | } 27 | 28 | var update = function() { 29 | currentScroll = latestScroll; 30 | isScroll = false; 31 | var helloScroll = currentScroll / 4, 32 | blurScroll = currentScroll * 2; 33 | 34 | hello.style.transform = 'translate3d(0, ' + helloScroll + 'px, 0)'; 35 | blur.style.opacity = (blurScroll / windowHeight - .1).toFixed(2); 36 | if(blur.style.opacity >= 1) { 37 | blur.style.opacity = 1; 38 | } 39 | } 40 | 41 | init(); 42 | })(); -------------------------------------------------------------------------------- /images/autumn-blur.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harayu/Blur-effect-on-scroll/20d96746f61a344ee509029c6d1e9afb3a7e0a23/images/autumn-blur.jpg -------------------------------------------------------------------------------- /images/autumn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/harayu/Blur-effect-on-scroll/20d96746f61a344ee509029c6d1e9afb3a7e0a23/images/autumn.jpg -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Blur effect on scroll 5 | 6 | 7 | 8 | 9 |
10 |
11 |
12 |

Blur effect

13 |

Modern Life Is Rubbish

14 |
15 |
16 |
17 |
18 |
19 |

created by harayu

20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | html, body { 3 | margin: 0; 4 | padding: 0; 5 | } 6 | html { 7 | font-size: 62.5%; 8 | font-family: 'Vollkorn', "Hiragino Kaku Gothic ProN", serif; 9 | } 10 | *, *::before, *:after { 11 | box-sizing: border-box; 12 | } 13 | a { 14 | text-decoration: none; 15 | color: #000; 16 | } 17 | h1 { 18 | /*text-rendering: optimizelegibili;*/ 19 | margin: 0; 20 | font-size: 8rem; 21 | color: #fff !important; 22 | } 23 | p { 24 | font-size: 3rem; 25 | } 26 | header { 27 | position: relative; 28 | overflow: hidden; 29 | width: 100%; 30 | height: 100vh; 31 | background: url(images/autumn.jpg) no-repeat; 32 | background-size: cover; 33 | } 34 | .hello { 35 | position: absolute; 36 | top: 0; 37 | right: 0; 38 | bottom: 0; 39 | left: 0; 40 | z-index: 1; 41 | } 42 | hgroup { 43 | display: inline-block; 44 | text-align: center; 45 | position: absolute; 46 | width: 50%; 47 | top: 0; 48 | right: 0; 49 | bottom: 0; 50 | left: 0; 51 | height: 211px; 52 | margin: auto; 53 | color: #fff; 54 | z-index: 2; 55 | } 56 | .overlay { 57 | position: absolute; 58 | top: 0; 59 | right: 0; 60 | bottom: 0; 61 | left: 0; 62 | background: url(images/autumn-blur.jpg) no-repeat; 63 | background-size: cover; 64 | z-index: 0; 65 | opacity: 0; 66 | } 67 | .about { 68 | width: 100%; 69 | height: 100vh; 70 | padding: 80px; 71 | text-align: center; 72 | } --------------------------------------------------------------------------------