How can I prevent the rectangle from moving out of my canvas..... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I prevent the rectangle from moving out of my canvas.....

How...? Suggest me an idea... https://code.sololearn.com/WJlw8ql2lJ2d/?ref=app

19th Jul 2020, 1:55 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
5 Answers
+ 2
You can use if statement to move only if it doesn't pop out. : https://code.sololearn.com/W03R9BDAGnFn/?ref=app You have written the wrong names for left and right. :-D
19th Jul 2020, 2:08 PM
Arnesh
Arnesh - avatar
0
Thank you.. Is there any alternative
19th Jul 2020, 2:32 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
Arnesh I can't understand the code,sorry. Can you please explain what is getBoundingClientRect, Or suggest me another alternative..
19th Jul 2020, 2:40 PM
Mustafha Ahmad
Mustafha Ahmad - avatar
0
Get Bounding Client rect returns an object with an element dimension, position, etc. It returns the current position, size, etc. Not the css. https://code.sololearn.com/W2uo8W0y8MLV/?ref=app
19th Jul 2020, 2:50 PM
Arnesh
Arnesh - avatar
0
Ok
19th Jul 2020, 3:33 PM
Mustafha Ahmad
Mustafha Ahmad - avatar