Kelios naudingos funkcijos dirbant su div (1 part)
Bir.02, 2007 in
Javascript, Programavimas, WEB programavimas
Dauguma šių funkcijų tinka ne tik div’am.
Norėdami dirbti su divu, turite jam priskirti id
-
gražina į kintamajį elementą. Ją naudosiu tolesnėse funkcijose
-
function getelement(element) {
-
return document.getElementById(element);
-
}
-
//parodomo diva (veiks jeigu paslepimui naudojote stiliu: "display:none";
-
function showdiv(name) {
-
div=getelement(name);
-
div.style.display=‘block’;
-
return true;
-
}
-
//paslepia diva
-
function hidediv(name) {
-
div=getelement(name);
-
div.style.display=‘none’;
-
return true;
-
}
-
//keičia div rodymo/paslėpimo buseną. Tarkim paslėptą divą parodys, o matomą, paslėps.
-
function swap_content(name){
-
displayType=(document.getElementById(name).style.display==‘none’) ? ‘block’:‘none’;
-
document.getElementById(name).style.display=displayType;
-
return true;
-
}
-
//pakeičiam div’o turinį
-
function writetodiv(div,text) {
-
document.getElementById(div).innerHTML=text;
-
return true;
-
};
-
//Diva nusiunčiam į centrą. Būtinai reikės funkcijų gauti lango dydžiui: <a href="http://blog.neworldwar.com/?p=42">jas rasite čia</a>
-
function setContent(content) {
-
if (document.getElementById) {
-
var windowHeight = getWindowHeight();
-
var windowWidth = getWindowWidth();
-
if (windowHeight > 0) {
-
var contentElement = document.getElementById(content);
-
var contentHeight = contentElement.offsetHeight;
-
var contentWidth = contentElement.offsetWidth;
-
if (windowHeight - contentHeight > 0) {
-
contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + ‘px’;
-
contentElement.style.left = ((windowWidth / 2) - (contentWidth / 2)) + ‘px’;
-
}
-
}
-
}
-
return false;
-
}


Palikti komentarą