Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Using canvas and mousemove I create a masking effect.

Example: FIDDLE

The masking effect works but on fast scrolling performance isn't ideal.

How can I improve the framerate?

share|improve this question

migrated from programmers.stackexchange.com Apr 29 '13 at 21:10

This question came from our site for professional programmers interested in conceptual questions about software development.

1  
Programmers.SE is typically for questions of higher level design issues (data structures, architecture, licensing, algorithms, testing, etc..). When you start dealing with implementation details and bug fixes, it becomes more appropriate for SO than P.SE. – user289086 Apr 29 '13 at 21:29
up vote 1 down vote accepted

I fixed it simply by using the window mouse coordinates, instead of the listener on the canvas (assuming you want the picture to just be black).

http://jsfiddle.net/gfZ5C/166/

I also changed to requestAnimationFrame, you'll notice a complete FPS difference in the movement of the circle, instead of it moving according to the listener.

window.onmousemove = function (e) {
    circle.posX = e.pageX-can.offsetLeft;
    circle.posY = e.pageY-can.offsetTop;
    circle.hide = (circle.posX >= 550 || circle.posY >= 550) ? true : false;
}
if (!circle.hide) ctx.arc(circle.posX, circle.posY, 70, 0, Math.PI * 2, true);

I left it at 550, so that you could see it actually disappear, you can change it to a big number if you want the circle to just drag right off the canvas.

Also there is no lag on the circle following the mouse now.

Update: Fixed the fiddle so that the circle adjusts for window offset too. The offset is relevant to its parent element, so depending on how far deep your canvas is, you will have to subtract each elements offset that it is inside.

Update: Switched to handle 'onmouse' events, this will work much better on a real site, because mousing over the iFrame doesn't work well, but it still works. Will work 100% as intended on a real site.

share|improve this answer
    
@Aaron Updated my answer / fiddle. – Datsik Apr 30 '13 at 0:16
    
@aaron if I answered your question you should mark answered, and if you have more questions not pertaining to this specific question you need to make a new question :-) – Datsik Apr 30 '13 at 12:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.