Created
March 12, 2019 10:09
-
-
Save nanna-dk/36709201de012af5bbc720297e8de7bc to your computer and use it in GitHub Desktop.
Change opacity of an area based on mouse position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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