0

I implemented a script from codecanion in my website and it works ok but I have one problem: When I scroll down the light emitng spot from the canvas doesn't correspond anymore to my cursor. So the cursor is lower than the light emitting spot. The page will ahve many other sections.

https://nlight-mediacreative.rhcloud.com

http://prntscr.com/cmp393

How to solve this?

Many thanks

Alex Stanese
  • 735
  • 4
  • 16
  • 33

1 Answers1

0

Subtract window.scrollY from the mouse coordinates. You should also do the X is there is any horizontal scrolling.

As window is the global object you do not need to name it

mouse.x -= scrollX; 
mouse.Y -= scrollY; 

is same as

mouse.x -= window.scrollX; 
mouse.Y -= window.scrollY; 
Blindman67
  • 51,134
  • 11
  • 73
  • 136
  • Thank you very much for your response. I'm pretty new to javascript. Could you please show me a jsfiddle? Thanks – Alex Stanese Sep 26 '16 at 22:04
  • I am guessing you want to know where in the script that you have inserted in your website, you need to change it to make it do what you want. As I understand it codeCanyon sells scripts, your best option is to contact the author/codeCanyon to fix bugs or make changes. Sorry but Stackoverflow is not a code writing service. – Blindman67 Sep 26 '16 at 22:36
  • Hi. The script is a freebe from codepan. The first thing I tried it to contact the author but he doens't respond at all. I changed as you menioned in function mousemove(event). It works fine for Y, however for X when I move in the right side of the screen there's an offset, if I move to the left side of the screen there's no more offset. How to solve this one too? left: http://prntscr.com/cmxzyk right: prntscr.com/cmxyb7 Thanks – Alex Stanese Sep 27 '16 at 13:03