/    Sign up×
Community /Pin to ProfileBookmark

calculate CSS margin-top Property

i need some help with this script.
for the id ‘section1’
i want to calculate the css margin-top property.
the margin-top equals the available screen height minus 920px.

hope someone can give a hint.

<script type=”text/javascript”>
$(window).load(function(){
$(window).resize(function(){
AvailHeight = window.screen.availHeight
var topmarge1 = AvailHeight – 920
$(‘#section1’).css(‘margin-top’, topmarge1+”px”); // <– set here
});
$(window).resize();
});
</script>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@007JulienFeb 04.2012 — See this page about a cross browser getStyle function which can probably give the margin-top without jQuery.
Copy linkTweet thisAlerts:
@mrhooFeb 04.2012 — For someone using a mobile device, or a screen with less than 920 px height, the margin will be negative, and the top part of section1 will be be outside the visible window.
Copy linkTweet thisAlerts:
@gaudiauthorFeb 05.2012 — i first do a browserdetection and redirectin using javascripting.

it is not a usual website .. it's a website with a jQuery horizontal scrolling script. http://www.primastyle.com/bertbril

#section1 is the homepage

#section2 is the page 'aanbod'

#section3 is the contact page

etc etc

so i have to work with a position which is absolute.

i don't think i can do it with getStyle.

but how is my syntax ?

because working with avalHeight is what i think the only possibility to verticalcenter my pages.
Copy linkTweet thisAlerts:
@007JulienFeb 05.2012 — You want apparently to set (not to calculate) the css property and to show your original pages. Then AvailHeight seem a good cross browser property, like shown on this page.
×

Success!

Help @gaudi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...