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 trialAnthony Ho
10,228 PointsI want to use the slider to change the thickness of the brush
This is what I got so far, but it doesn't work:
function changeThickness(){
var x = $("#thickness).val();
context.lineWidth = x;
}
$("input[type=range]").on("input", changeThickness);
2 Answers
Chad Dugas
Courses Plus Student 13,304 PointsYou need to do something like this:
$("#thickness").on("input", function() {
context.lineWidth = $("#thickness").val();
});
context.lineCap = "round";
And your HTML should look something like this:
<p>
<label for="thickness">Thickness</label>
<input id="thickness" name="thickness" type="range" min=1 max=50 value=1>
</p>
You can replace your whole function with that. Also you need to make the lineCap = "round". If you don't then the thick line you draw will be a collection of tiny lines. You can put that part anywhere in your program. It doesn't need to be inside a function or event.
Andrew Chalkley
Treehouse Guest Teacher"#thickness
You're missing a "
at the end :)
Anthony Ho
10,228 Pointsstill doesn't work though Please give me some hints. I appreciate it.
Anthony Ho
10,228 PointsAnthony Ho
10,228 PointsThanks a lot. Right now I'm trying to change the cursor for only the rubber. Here is what I got so far:
Chad Dugas
Courses Plus Student 13,304 PointsChad Dugas
Courses Plus Student 13,304 PointsI'm not totally sure I understand what you are trying to do, but I think you should try using the jQuery method .hasClass.
So your code would look like this:
Also, I don't think you need you need to set the cursor to none, then assign it to the eraser image. You could probably omit that first line so it becomes: