Relative positioning with jQuery


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
17 views
Help positioning the elements relative to each other scrolling in different browsers.

Did an additional unit when you move the mouse. Here is the piece of code responsible for calculating the position of the new block on the page:

...

var mytop = image.offset().top - (container.height() /2) + image.height()/2 + $(document).scrollTop();
var myleft = image.offset().left - (container.width() /2 ) + image.width()/2 + $(document).scrollLeft();

if($.browser.msie){
mytop = image.offset().top - (container.height() /2) + image.height()/2;
myleft = image.offset().left - (container.width() /2 ) + image.width()/2;
}

container.offset({top: mytop, left: myleft});
container.show();

...


Ie look at the coordinates of the current element, and if the browser is IE, then add the height/width of the scrolling.

Just yesterday whether chrome is updated, or jQuery (the last loads from Google CDN), but Chrome started to add scroll (IE it may appear to be). Maybe there's a way to position an element without prescribing all versions of "glyuchaschie" browsers?
by | 17 views

3 Answers

0 like 0 dislike
In jQuery, everything is fine, changed the interpretation of chrome, now it does not compensate for scrolling.
by
0 like 0 dislike
It obserable or innovations in webkit?
by
0 like 0 dislike
Try to use (mutatis mutandis) method $(...).position() method instead of $(...).offset(), if it is allowed by the conditions of the problem.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
6 answers
asked Mar 24, 2019 by rumkin
110,608 questions
257,186 answers
0 comments
27,880 users