Creating blur effect with css and jQuery on scroll

前端 未结 2 2051
暖寄归人
暖寄归人 2021-01-04 18:54

I am trying to create blur effect when the user scrolls up and down the browser window using css and jquery. Here is my code.

HTML

&         


        
相关标签:
2条回答
  • 2021-01-04 19:01

    For "blur" effect , try utilizing css filter blur(Npx) , where N is a number; px css pixel units e.g.; 4px

    var hideThatKitty = $('.out').innerHeight();
    
    $(window).on('scroll', function () {
        hideThatKitty = hideThatKitty / $('.this-div-kills-browsers').offset().top
        $('.out')
        .css({"webkit-filter": "blur(4px)",
              "moz-filter":"blur(4px)",
             "ms-filter":"blur(4px)",
             "o-filter":"blur(4px)",
             "filter":"blur(4px)"});
    });
    .out {
        width: 100%;
        height: 800px;
        background: url(https://placekitten.com/1200/800) no-repeat;
    }
    .this-div-kills-browsers {
        height: 1000px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
    </script>
    <div class="out">
        <div class="inner"></div>
    </div>
    <div class="this-div-kills-browsers"></div>

    jsfiddle https://jsfiddle.net/2dmxLnuy/5/

    0 讨论(0)
  • 2021-01-04 19:21

    Scrolling while bluring an image

    Demo

    https://jsfiddle.net/vduucu87/

    Code

    $(window).on('scroll', function () {
        var pixs = $(document).scrollTop()
        pixs = pixs / 100;
        $(".out").css({"-webkit-filter": "blur("+pixs+"px)","filter": "blur("+pixs+"px)" })     
    });
    
    0 讨论(0)
提交回复
热议问题