Thursday, February 9, 2017

jQuery - never call offset() method on hidden element

In jQuery, a call to .offset() method of a hidden element might lead to wrong coordinates being obtained.

For example, this code is going to produce wrong results:


jQuery(".hover-gallery").offset( jelem.offset() );
jQuery(".hover-gallery").show();

The correct way to do it:

jQuery(".kd-hover-gallery").show();
jQuery(".kd-hover-gallery").offset( jelem.offset() );

More info here:
http://stackoverflow.com/questions/12087670/jquery-offset-top-doesnt-work-correctly

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...