Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Beginner
Mar 14, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Use Appropriate Properties for CSS Positioning

When using CSS (Cascading Style Sheets) positioning, you can apply a number of techniques to make your code faster. When accessing and setting the position of an element, instead of using element.style.left and element.style.top properties, you should use posLeft, posTop, posWidth, and posHeight properties. The problem is that the left property is returned as a string and if you want to do math on the returned value, then it first needs to be converted from a string to an integer.

The posLeft, posTop, posWidth, and posHeight properties are floating-point representations of their corresponding string property. By using these properties, you will write smaller and much faster code. Speed becomes more important when the position is constantly being updated to perform an animation effect.

Deepak Pant
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date