0

I'm working with Canvas and I'm trying to add centered text dynamically on a picture.

I read on this topic (How to add text on image using Javascript and Canvas), that I have to put some jQuery in my code. I tried but I did not succeed because I don't have a lot experience in jQuery.

You can find the example I made on the JSFiddle link below.

https://jsfiddle.net/ParkerIndustries/t3rao9hL/14/

1
  • Sorry, the mistake was in the fillText function. If you want to center horizontally, put width/2 in fillText as x position. So context.textAlign = 'center'; works but, I just set a bad position. Commented Aug 18, 2019 at 2:03

1 Answer 1

1

If you have to add in jQuery to your code ( besides having the jquery.min file loaded ), you precursor any code with the "$" symbol and then the element you are identifying ( wrapped in parenthesis ). In your case:

 $(context)

since you've already identified your element. Then after that there are a couple ways to change css using jQuery.

$(context).css({ 'display', 'none' });
$(context).addClass('changed');

If you don't have an identifier, just put it in quotes:

$('#context').addClass('changed');

For JavaScript, Clarity answered that in the comment above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.