简体   繁体   中英

Input range to regulate blur value

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<style>
.imgBlur{
    width:800px;
    float:left;
    height: 450px;
    background: url(img.jpg) no-repeat left center;
    -webkit-filter: blur(20px);
    -moz-filter: blur(20px);
    -o-filter: blur(20px);
    -ms-filter: blur(5px);
    filter: blur(20px);
    z-index: 1000;
}
</style>
<body class="body">
                        <input type="range" id="blurValue" class="blurValue" min="0" max="100" step="1"></input>

            <div class="imgBlur" id="imgBlur"></div>


        </script>
</body>
</html>

Hello everyone. My javascript is very poor and i am having trouble finding a solution online for my pickle here. I am trying to make this input range to adjust the value of the blurred div. Any help will be appreciated

Here is your required solution using onChange event

I have taken a function when range is changed,

 <input type="range" id="blurValue" class="blurValue" min="0" max="100" step="1" onChange="changed()"></input>

  function changed()
    {
      var obj = document.getElementById('imgBlur');
      obj.style["-webkit-filter"] = "blur("+document.getElementById("blurValue").value+"px)";
    }

This catches the range change event and changes the css using javascript

obj.style["-webkit-filter"] = "blur("+document.getElementById("blurValue").value+"px)";

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> </head> <style> .imgBlur{ width:800px; float:left; height: 450px; background: url("https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/03/1458289957powerful-images3.jpg"); -webkit-filter: blur(20px); -moz-filter: blur(20px); -o-filter: blur(20px); -ms-filter: blur(5px); filter: blur(20px); z-index: 1000; } </style> <body class="body"> <input type="range" id="blurValue" class="blurValue" min="0" max="100" step="1" onChange="changed()"></input> <div class="imgBlur" id="imgBlur"></div> <script> function changed() { var obj = document.getElementById('imgBlur'); obj.style["-webkit-filter"] = "blur("+document.getElementById("blurValue").value+"px)"; obj.style["-moz-filter"] = "blur("+document.getElementById("blurValue").value+"px)"; obj.style["-o-filter"] = "blur("+document.getElementById("blurValue").value+"px)"; obj.style["-ms-filter"] = "blur("+document.getElementById("blurValue").value+"px)"; obj.style["filter"] = "blur("+document.getElementById("blurValue").value+"px)"; } </script> </body> </html> 

Please run the above snippet

Here is a working DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM