CSS筛选器的效果更好的替代方法:blur()

时间:2018-08-23 16:59:59

标签: css reactjs svg html5-canvas blur

我开始致力于大量利用模糊效果的React项目。

它将图标添加到div中,并将其作为背景并使其模糊。

因此,每个具有不同图标的部分都有不同的创辉背景。

我已附上图片,因为我认为我对它的解释很差:

Screenshot of the website

我不确定要附加的代码部分,因此我将在这里放置影响它的react组件和css:

反应组件

import React from 'react';
import './Object.css';

const Jobs = ({ employer, description, descriptionList, image }) => {
    return (
        <div>
            <section className="object-container">
                <div className="container">
                    <div className="object">
                        <div className="row">
                            <div className="col-sm-8">
                                <h3 className="employer">
                                    {employer}
                                </h3>
                                <div className="description">
                                    {description}
                                </div>
                                <ul className="description-list">
                                    {descriptionList.map(item => <li>{item}</li>)}
                                </ul>
                            </div>
                            <div className="image-container">
                                <div className="col-sm-4">
                                    <img className="image" src={image} alt="logo" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div className="object__bg" id="object__bg" style={{ backgroundImage: `url(${image})` }}>
                </div>
            </section>
        </div >
    );
}

export default Jobs;

CSS

@font-face {
    font-family: 'Neon Online';
    src: url(I_am_online_with_u.ttf) format('truetype'),
        url(I_am_online_with_u.woff) format('woff');
  }

.object {
   padding: 40px; 
    background-color: rgba(53, 53, 53, 0.45);
    border-radius: 20px;
    box-shadow: 0px 3px 28px 1px rgba(0,0,0,0.75);
    color: white;
    display: flex;
    align-items: center;
    transform: scale(1);
    transition: all 0.15s ease-in;
        /* 
        This is used for improving performance with blur filter.
        Why does it work, I have no idea...
     */
     backface-visibility: hidden;
     perspective: 1000;
     transform: translate3d(0,0,0);
     transform: translateZ(0);
}

.object:hover {
    box-shadow: 0px 3px 32px 1px rgba(0,0,0,0.9);
    background-color: rgba(53, 53, 53, 0.55);
    transform: scale(1.01);
    transition: all 0.31s ease-out;
}

.object-container {
    position: relative; 
    padding: 40px;
    /* 
        This is used for improving performance with blur filter.
        Why does it work, I have no idea...
     */
    backface-visibility: hidden;
    perspective: 1000;
    transform: translate3d(0,0,0);
    transform: translateZ(0);
}

.object__bg  {
    position: absolute;
    z-index: -1;
    top: 0;
    left: -10vw;
    right: 0;
    margin: auto;
    width: 120vw;
    min-height: 100px;
    height: 100%;
    filter: blur(150px) saturate(2) hue-rotate(0deg);

    background-position: center center;
    background-size: cover;
    background-color: #353535;

    transition: all 1.5s ease-out;
}

.object__bg:hover,
.object__bg:focus {
    filter: blur(150px) saturate(2.6) hue-rotate(180deg);
    transition: all 3s ease-in;
}


.image-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.image {
 width:  200px;   
}

我想到了canvas和svg滤镜,因为我读过几次,它的模糊效果大大提高了性能。 不幸的是,尝试了几次之后,我只是无法使其与React一起使用。

我还尝试过在覆盖模糊的元素上增加背面可见性,这很有帮助(我不确定,这可能是因为它迫使GPU代替CPU来完成工作)。

那么,有没有其他替代方法可以帮助我建立一个利用模糊程度很高的网站?

0 个答案:

没有答案