Skip to content

Instantly share code, notes, and snippets.

@nanna-dk
Created March 12, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanna-dk/36709201de012af5bbc720297e8de7bc to your computer and use it in GitHub Desktop.
Save nanna-dk/36709201de012af5bbc720297e8de7bc to your computer and use it in GitHub Desktop.
Change opacity of an area based on mouse position
<!DOCTYPE html>
<html>
<head>
<style> .one{
opacity:.5;
}
</style>
</head>
<body>
<script src="https://ajax.googleapis.com/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.com/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.com/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>
<script type="text/javascript">
$('svg').on('mousemove', function(e) {
$('.a').attr('cx', e.pageX).attr('cy', e.pageY)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment