jquery - Is it possible to apply a blur filter to a background-image of a div with position:fixed, from another div rendered on top of it? -


how question different proposed duplicate:

i want only part of div.background-pic (the div background image) behind div.lower (the div translucent blue color), just appear be blurred.

explained:

as can see, div.background-pic position:fixed (which means out of flow, , not scroll), while rest of page scrolls vertically, implies there different parts of div.background-pic behind div.lower @ different times (while page being scrolled).

so obvious don't want div image itself, (apply kind of filter if there one, etc.) on div.lower such causes part of the background-image of div behind it, appear blurred.


question:

jsfiddle

in following sscce, want part of (background-image of) .background-pic behind .lower (and partially visible because .lower translucent) appear blurred out. possible?

.background-pic {    background-image: url(http://khongthe.com/wallpapers/nature/beautiful-valley-45851.jpg);    background-size: cover;    position: fixed;    z-index: -1;    height: 400px;    width: 400px;  }  .top-blur {    height: 400px;    width: 400px;    overflow: auto;  }  .upper {    height: 300px;    width: 100%;    background-color: rgba(255, 127, 80, 0.5);  }  .lower {    height: 200px;    width: 100%;    background-color: rgba(0, 255, 255, 0.51);  }
<div class="background-pic">      <div class="top-blur">      <div class="upper"></div>      <div class="lower"></div>    </div>    </div>

note: css solution preferred.


there's way js result, using clipping path , repositioning on scroll. this:

html:

<div class="background-pic-top"></div> <div class="background-pic-bottom"></div> <div class="top-blur" id="scrollingdiv">     <div class="upper">         <svg class="clip-svg" width="400" height="500" style="position: relative">             <defs>                 <clippath id="uppersvg" clippathunits="userspaceonuse">                     <rect x="0" y="0" width="400" height="300" />                 </clippath>             </defs>         </svg>     </div>     <div class="lower">         <svg>             <defs>                 <clippath id="lowersvg" clippathunits="userspaceonuse" width="200" height="200">                     <rect x="0" y="300" width="400" height="200" />                 </clippath>             </defs>         </svg>     </div> </div> 

js:

    var elem = document.getelementbyid('scrollingdiv');     var clipup = document.getelementbyid('uppersvg');     var clipdown = document.getelementbyid('lowersvg');      elem.onscroll = function (e) {         clipdown.getelementsbytagname('rect')[0].setattribute('y', 300 - elem.scrolltop);         clipup.getelementsbytagname('rect')[0].setattribute('y', 0 - elem.scrolltop);     } 

css:

   body {             margin: 0px;         }         .background-pic-top {             background-image:url(http://khongthe.com/wallpapers/nature/beautiful-valley-45851.jpg);             background-size:cover;             position:fixed;             z-index:-1;             height:400px;             width:400px;             clip-path: url(#uppersvg);             -webkit-clip-path: url(#uppersvg);         }         .background-pic-bottom {             background-image:url(http://khongthe.com/wallpapers/nature/beautiful-valley-45851.jpg);             background-size:cover;             position:fixed;             z-index:-1;             height:400px;             width:400px;             clip-path: url(#lowersvg);             -webkit-clip-path: url(#lowersvg);             -webkit-filter: blur(5px);             filter: blur(5px);         }         .top-blur {             height:400px;             width:400px;             overflow: auto;         }         .upper {             height:300px;             width:100%;             background-color: rgba(255, 127, 80, 0.5);         }         .lower {             top: 200px;             height:200px;             width:100%;             background-color: rgba(0, 255, 255, 0.51);         } 

http://jsfiddle.net/4f601tt7/7/

won't cross-browser seems work on chrome , firefox.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -