Home >Web Front-end >uni-app >Use uniapp to achieve picture blur effect

Use uniapp to achieve picture blur effect

WBOY
WBOYOriginal
2023-11-21 13:30:431935browse

Use uniapp to achieve picture blur effect

Use uniapp to achieve picture blur effects

With the development of mobile applications, more and more applications need to add picture blur effects to improve user experience. In the uniapp development framework, we can achieve the image blur effect through some simple codes.

  1. Introduce pictures
    First, add a file in the static directory of the uniapp project or the static directory of uniapp A picture that needs to be blurred, for example named blur.jpg.
  2. Display pictures on the page
    Add the following code in the template tag of the page where the picture needs to be displayed:
<template>
  <view class="container">
    <image src="../../static/blur.jpg" class="blur-img"></image>
  </view>
</template>
  1. Add CSS style
    Add the following CSS style in the style tag of the same page or in the public style file:

    <style>
      .container {
     display: flex;
     justify-content: center;
     align-items: center;
     height: 100vh;
      }
    
      .blur-img {
     width: 300px;
     height: 300px;
     filter: blur(5px);
      }
    </style>

In the above code, style.blur-img is the key, by setting its filter: blur(5px) to achieve the blur effect of the image. 5px is the degree of blur, you can adjust it as needed.

  1. Run and preview the effect
    Run the project through the uniapp development tool, and then you can see the image with the blur effect added on the page.

Summary:
Through the above code examples, we can see that it is very simple to achieve the image blur effect under the uniapp development framework. Use the filter: blur(5px) attribute to easily achieve the blur effect of the image. We can adjust the degree of blur according to our own needs to achieve the desired effect. I hope this article will help you understand and use uniapp to achieve image blur effects.

The above is the detailed content of Use uniapp to achieve picture blur effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn