Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center position of current screen position

Tags:

javascript

Is there an option to find center position (top and left) of an actual screen position?

My main goal is to show div in the center of the screen no matter where i scroll or click

like image 257
user6769617 Avatar asked Mar 11 '23 07:03

user6769617


1 Answers

You can use window attributes to get center coordinates in pure javascript:

var x = window.innerWidth / 2;
var y = window.innerHeight / 2;
like image 117
joc Avatar answered Mar 20 '23 18:03

joc