How to make a SVG Blur the Page content on mouse scroll for both Desktop and Mobile?

橙三吉。 提交于 2021-01-07 01:08:20

问题


The code works on Desktop but really sucks on Deceives so I assume I’m missing something. Iv read stuff and tried other hacks but I’m getting frustrated of reading and not understanding.

https://codepen.io/mikeloucas/pen/yLaYYGV

The scroll FX doesn't work while swiping up or down, it activates after I stop and then it stutters in and out. So odd. It worked in the Browsers emulator but this is not a TRUE device.

If any one could help, great!

html-svg part

    <svg style="position: absolute; top:-99999px" xmlns="http://www.w3.org/2000/svg">
      <filter id="svgBlur" x="-5%" y="-5%" width="110%" height="110%">
       <feGaussianBlur id="fltBlur" in="SourceGraphic" stdDeviation="0" />
      </filter>
    </svg>

    <div id=cont>
What is Lorem Ipsum?
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    <br />
Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    
    <br />
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
    <br />
Where can I get some?
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
    </div>

css part

    #cont {
    width:50%;
    font-size:2em;
    -webkit-filter: url(#svgBlur);
    filter: url("#svgBlur");
    -mos-filter: url(#svgBlur);
    -ms-filter: url(#svgBlur);
    -o-filter: url(#svgBlur);
     }

javascript part

//start the Blur
var blur = document.getElementById("fltBlur");
var prevY = 0;
var reqId;

//stop the Blur when not scrolling
window.onscroll = function() {
  cancelAnimationFrame(reqId);
  reqId = requestAnimationFrame(motionBlur)
    
      clearTimeout(this, 'scrollTimer');
    (this, 'scrollTimer', setTimeout(function() {
      var y = window.scrollY;  
            var n = Math.min(0, Math.abs(y - prevY));
  blur.setAttribute("stdDeviation" ,"0 " + n);
  prevY = y;
        console.log("Haven't scrolled in 0ms!");
    }, 0));
};

//Blur while scrolling
function motionBlur() {
  var y = window.scrollY;
  var n = Math.min(32, Math.abs(y - prevY));
  blur.setAttribute("stdDeviation" ,"0 " + n);
  prevY = y;
}

来源:https://stackoverflow.com/questions/65109026/how-to-make-a-svg-blur-the-page-content-on-mouse-scroll-for-both-desktop-and-mob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!