javascript - Change opacity of an area based on mouse position - Stack Overflow

Is it possible to change the opacity of background but only underneath the cursor area (for example a w

Is it possible to change the opacity of background but only underneath the cursor area (for example a white small circle)? I am thinking of it a bit like a basic heatmap but the heat doesn't stay - it just follows the cursor.

At the moment I have the following

HTML:

html {
  background-color: #000;
  width: 100%;
  height: 100%;
}

JS:

$(document).mousemove(function(event){
    var i = event.pageX.toPrecision(1) / 1000;
    $("html").css('opacity', i)
});

Sorry this is probably a very basic starting point. Would I need to use canvas?

Is it possible to change the opacity of background but only underneath the cursor area (for example a white small circle)? I am thinking of it a bit like a basic heatmap but the heat doesn't stay - it just follows the cursor.

At the moment I have the following

HTML:

html {
  background-color: #000;
  width: 100%;
  height: 100%;
}

JS:

$(document).mousemove(function(event){
    var i = event.pageX.toPrecision(1) / 1000;
    $("html").css('opacity', i)
});

Sorry this is probably a very basic starting point. Would I need to use canvas?

Share Improve this question asked May 7, 2015 at 11:32 xylarxylar 7,67317 gold badges59 silver badges105 bronze badges 1
  • 1 related: stackoverflow./questions/27864499/… – jbutler483 Commented May 7, 2015 at 11:54
Add a ment  | 

1 Answer 1

Reset to default 9

You can do that using svg

What i did :-

I placed two same images with same co ordinates,height and width and gave a circular clip-path to the one on top (which has full opacity) when mouse moves the position of the circle also changes

$('svg').on('mousemove',function(e){
    $('.a').attr('cx',e.pageX).attr('cy',e.pageY)
      
})
.one{
    opacity:.5;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg width="500" height="500">
    <clippath id="clip" >
        <circle cx="50" cy="50" r="50" class="a"/>
    </clippath>
    
    <image xlink:href="https://images.unsplash./photo-1474575981580-1ec7944df3b2?dpr=1&auto=format&fit=crop&w=1500&h=934&q=80&cs=tinysrgb&crop=&bg=" width="500" height="500" x="0" y="0"   class="one"/>
     
   <image xlink:href="https://images.unsplash./photo-1474575981580-1ec7944df3b2?dpr=1&auto=format&fit=crop&w=1500&h=934&q=80&cs=tinysrgb&crop=&bg=" width="500" height="500" x="0" y="0" clip-path="url(#clip)"/>
  </svg>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744396998a4572191.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信