Advertisement
kstoyanov

05. Mouse Gradient

Oct 1st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function attachGradientEvents() {
  2.     const el = document.getElementById('gradient');
  3.     const resultDiv = document.getElementById('result');
  4.  
  5.     el.addEventListener('mousemove', function(e){
  6.         const mouseX = e.offsetX;
  7.         const percentage = Math.floor(Number(mouseX) / 300 * 100);
  8.         resultDiv.textContent = percentage.toString() + '%';
  9.     });
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement