when the text move diagonally if (postiony >= windowHeight - text.offsetHeight || postiony <= 0) {
if (postiony >= windowHeight - text.offsetHeight) {
postiony = windowHeight - text.offsetHeight - 1;
} else {
postiony = 1;
}
speed *= -1;
}
if (postionx >= windowWidth - text.offsetWidth || postionx <= 0) {
if (postionx >= windowWidth - text.offsetWidth) {
postionx = windowWidth - text.offsetWidth - 1;
postionx = 1;
}
speed *= -1; the text just passes though the height a lttle bit , and how to make it bounce in the ooposite direction? like if the inital positon is x=0y=0 it will go diagonal to the down right and it bounces to the make it up right
To make text move diagonally within a window and bounce when it reaches the edges. Try this code: