Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 5

So the error appears to be that the event cannot detect OffsetX.

The code is:

//No user interaction causes no change to application //When the user is interacting cause a change to occur

//Even though the class selected doesn't have a bg color,it also has a class of color with it with a background with it (DO NOT GET CONFUSED) var color=$(".selected").css("background-color"); var $canvas=$("canvas"); var context=$canvas[0].getContext("2d"); var lastEvent; var mouseDown=true;

$("#newColor").css("background-color", "black");

$(".controls").on("click", "li", function(){ //Deselect selcted elements $(this).siblings().removeClass("selected");

//Select the clicked on element $(this).addClass("selected");

//Change the color after ranges

//This sets the color to the neccesary color chosen var color=$(this).css("background-color"); });

$("#revealColorSelect").click(function(){

/*if ( $("#colorSelect").css('display') == 'none' ){

//If element is hidden
$("#colorSelect").show();
// element is hidden

} else{ $("#colorSelect").hide(); }*/
changeColor(); $("#colorSelect").toggle();

});

function changeColor(){ var r=$("#red").val(); var b=$("#blue").val(); var g=$("#green").val(); var c= r+g+b; $("#newColor").css("background-color", "rgb(" + r + "," + b + "," + g + ")"); }

$("input[type=range]").change(changeColor);

//I need to append an li element with the color in the background of #newcolor //It also takes the same properties as the classes red blue and yellow

$("#addNewColor").click(function(){ var $newColor=$("<li></li>"); $newColor.css("background-color", $("#newColor").css("background-color")); $(".controls ul").append($newColor); });

$canvas.mousedown(function(e){ lastEvent=e; }).mousemove(function(e){ if(mouseDown){ context.beginPath(); context.moveTo(lastEvent.offsetX,lastEvent.offsetY); context.lineTo(e.offsetX, e.offsetY); context.stroke(); lastEvent=e; } }).mouseup(function(){ mouseDown=false; });

Has is been deprecated? Even autocomplete doesn't seem to detect it!

1 Answer

Steven Parker
Steven Parker
231,275 Points

:point_right: Your issue may be with mouse handling.

I notice that on the mouseup event, you set the global variable "mouseDown" to false. But on the mouseup event, you do not set it to true. So once you release the mouse, you cannot draw again.

I tested the code and it did exactly that. Otherwise, it seemed to perform as expected for this stage of the development.

Yes! Silly mistake. Thank you :D