27 kw. 2016

Wyśrodkowanie tabeli z danymi do rozmiaru okna

$(window).resize(function() {
var winW = $(window).width();
var conW = parseInt($('#container').css('width'));
var tabW = parseInt($('table.list').css('width'));

if(winW>conW) {
var margin_left = -((tabW - conW)/2)-10;
$('table.list').css({'margin-left':margin_left});
} else {
$('table.list').css({'margin-left':0});
}
});
$(window).resize();

Tabelka normalna:
tabela

Tabelka wyśrodkowana:
tabela wyśrodkowana

25 lut 2009

Zaokrąglanie liczby w JS

alert(n_height);

---------------------------
Windows Internet Explorer
---------------------------
811.267175572519
---------------------------
OK  
---------------------------

n=(Math.ceil(n_height*100))/100;
alert(n);

---------------------------
Windows Internet Explorer
---------------------------
811.27
---------------------------
OK  
---------------------------

n_height  = parseInt(n_height);

---------------------------
Windows Internet Explorer
---------------------------
811
---------------------------
OK  
---------------------------