I'm trying to write a jQuery script to place a div block in the center of the screen. The problem is that a div block I pass to this function is kinda badly styled or something and div.width(), div.outerWidth(), div.outerWidth(true), div.innerWidth()
all return the same wrong value of 1839px that is a $(window).outerWidth()
value. I can't figure out where I made a mistake? Please, help!
Here is a code:
function absoluteCenter(div) {
var winWidth = $(window).outerWidth(true);
var winHeight = $(window).outerHeight(true);
var divWidth = $("#"+div).outerWidth(true);
var divHeight = $("#"+div).outerHeight(true);
alert(divWidth);
$("#"+div).css({'position':'absolute', 'left':(winWidth/2 - divWidth/2), 'top':(winHeight/2 - divHeight/2)});
}
/* MAIN JS FILE TO INCLUDE ALL WRITTEN FUNCTIONS */
$(document).ready(function(){
diagonalize('about_container', 1, 'about_block');
diagonalize('products_container', -1);
absoluteCenter('about_block');
scrollOnClick('to_about', 'about_container');
crollOnClick('down_arrow', 'about_container');
scrollOnClick('to_products', 'products_container');
});
HTML:
<div id="second_screen">
<div id="about_container">
<div id="about_block">
TROUBLE
</div>
</div>
</div>
Main SASS file:
/* MAIN STYLE FILE OF LANDING PAGE */
/* STYLES FOR LANDING SCREENS WRAPPERS ARE HERE */
@import libs/hover/hover
@import colors
@import mixings
@import fonts
@import texts
@import menu
@import extends
@import landing_screen
@import about_screen
@import products_screen
body
margin: 0
padding: 0
background-image: url("../res/landing-background.png")
+background_cover
// landing screens wrappers
#first_screen, #second_screen, #third_screen
@extend .screen_wrapper
Also I'm using diagonalize script skew div blocks (see a screenshot for a reference):
function diagonalize(div, direction, compensation_div) {
var degree = Math.atan(0.13*$(window).width()/$(window).height())* (180/Math.PI);
if(direction === -1) degree = -degree;
$("#"+div).css({'-webkit-transform': 'skew('+degree+'deg)', '-moz-transform': 'skew('+degree+'deg)', '-o-transform':'skew('+degree+'deg)'});
$("#"+compensation_div).css({'-webkit-transform': 'skew(-'+degree+'deg)', '-moz-transform': 'skew(-'+degree+'deg)', '-o-transform':'skew(-'+degree+'deg)'});
}