Joshc
Joshc

Reputation: 3853

jQuery: get inline style top position value into a variable

The style attribute always stumps me, because there are many values in the style attribute. Anyway, please see below my markup I'm trying to adjust...

<div class="fancybox-wrap fancybox-default fancybox-opened" tabindex="-1" style="width: 798px; height: 542px; position: fixed; top: 82px; left: 20px; display: block; ">

As you can see I am trying to adjust the style: top: 82px; value. How can I get this value so I can add a value onto of it? Please see below the instance in how I am using this.

I would like the currentTop variable to some how get the current top inline position of the .fancybox-wrap div?

$("a.gallery-thumb").fancybox({
  afterLoad : function() {
    FB.Canvas.getPageInfo(function(info) {
      var scrollPosition = info.scrollTop,
      currentTop = /* how can I get the current top inline position? */ ;
      $('.fancybox-wrap').css('top', (scrollPosition + currentTop) + 'px');
    });
  }
});

Upvotes: 0

Views: 4721

Answers (2)

Sridhar Narasimhan
Sridhar Narasimhan

Reputation: 2653

You can get it using the below

$('.fancybox-wrap').css('top'); 

and sum it with the scrolltop.

Upvotes: 2

koopajah
koopajah

Reputation: 25562

Try this :

$('.fancybox-wrap').css('top', '+='+scrollPosition +'px');

Upvotes: 2

Related Questions