Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application More Mouse Events

Perfecting the drawing app

Instead of firing the mouseup event you can just set the mouse down to false.. so mouseleave(function(){ mouseDown = false; });

1 Answer

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

You could do that, but imagine if the code got more complicated when you finish drawing. It may be simple to change mouseDown = x in two places right now but it could get hairy.

Maybe you could have a function called finishDrawing()...

function finishDrawing(){
  mouseDown = false;
}

...

.mouseup(finishDrawing).mouseleave(finishDrawing);

Then you only have to edit the code in one place. I just wanted to illustrate triggering an event in the video :)

Regards
Andrew