Is there any way to colorize only part of image on hover?

前端 未结 4 1820
情深已故
情深已故 2021-02-06 18:51

I would love to code simple image painting in HTML, CSS and probably jQuery also.

Let\'s say I have a original image, and I want make it colorized but only in part of ho

4条回答
  •  -上瘾入骨i
    2021-02-06 19:32

    You can wrap you image in a HTML Element and add a div element element with box-shadow

    $("figure").on('mousemove', function(e){
        $('.shadow').css({
           left: e.pageX - $(this).offset().left - 40,
           top: e.pageY - $(this).offset().top -40
        });
    });
    figure{
        position: relative;
        margin: 20px auto;
        width: 480px;
        height: 480px;
        overflow: hidden
    }
    figure:hover .shadow{
        opacity: 1
    }
    img{
        width: 100%
    }
    
    .shadow{
        position: absolute;
        left: 80px;
        top: 60px;
        z-index: 1;
        background: transparent;
        width: 100px;
        height: 100px;
        opacity: 0;
        transition: opacity .3s ease;
        border-radius: 50%;
        box-shadow: 0 0 0 60em rgba(0,0,0,.5)
    }
    
    

提交回复
热议问题