1

I am using this code to do a vertical scroll, and it works fine:

$('.flapleftclass').css('top',(0+(scrolled*0.5))+'px');

It works because I am referencing to the top. This (below) works for horizontally, but '.flapleftclass' changes x-value to what screen size you have. What I need is to find the center of the screen (50%). Is that possible? (like put 50% instead of 960 (as it is right now))

$('.flapleftclass').css('left',(960+(scrolled*0.5))+'px');
Rasmus
  • 366
  • 1
  • 3
  • 19
  • 2
    java != javascript. Did you mean java, or javascript? – Mar Feb 28 '14 at 21:36
  • possible duplicate of [how to get web page size, browser window size, screen size in a cross-browser way?](http://stackoverflow.com/questions/3437786/how-to-get-web-page-size-browser-window-size-screen-size-in-a-cross-browser-wa) – Mar Feb 28 '14 at 21:38
  • you can actually do by left:50%, but your scrolled*0.5 px need to be unified. You better change to the scrolled*0.5 px to percentage as well – SCV Feb 28 '14 at 21:38
  • Thanks to your fast answers everyone! I cant make an answe (not enought reputation) so please do it for me: Thanks to Martin Carneys link I did a simple rewriting and it works: $('.flapleftclass').css('left',($(document).width()/2+(scrolled*0.3))+'px'); – Rasmus Feb 28 '14 at 21:47

1 Answers1

0

Thanks to Martin Carneys link I did a simple rewriting and it works:

$('.flapleftclass').css('left',($(window).width()/2+(scrolled*0.5))+'px');
Rasmus
  • 366
  • 1
  • 3
  • 19