PHP gevorderde |
|
@thomasje: ik zou je echt aanraden om tutorials te lezen. Iframes zijn niet voor CSS noch JS!
Je gebruikt om CSS te gebruiken in (X)HTML het volgende:
<link rel="stylesheet" href="test.css" type="text/css" />
<link rel="stylesheet" href="test.css" type="text/css" />
En voor JS gebruik je:
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript" src="test.js"></script>
Tenminste in XHTML.
Deze lijntjes komen terecht in de <head></head>. Javascript kan ook doorheen de <body></body> maar ik raad aan om JS bestanden in de <head></head> te zetten en javascript enkel puur(dus geen bestanden) te gebruiken in de <body></body>.
Maar wat zit nou in dat JS bestand?
Daar horen normaal allerlei functies in te zitten. Een CSS bestand bevat gewoon de opmaak van je webpagina.
Hoe gebruik ik dan dat wat in dat JS bestand zit?
Simpel, door de functies aan te roepen. Dit is een ander deel van je script... Deze functies zet je dan ook tussen <script type="text/javascript"></script>
Dus:
webpagina.html of .php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
<script type="text/javascript" src="moduleMenu.js"></script>
</head>
<body>
<script type="text/javascript">
var buttonFolder = "buttons"; // Set button's folder here.
// Set the button's filenames here.
upSources = new Array("button1up.png","button2up.png","button3up.png","button4up.png");
overSources = new Array("button1over.png","button2over.png","button3over.png","button4over.png");
// Sub menu declaration (No modification required)
subInfo = new Array();
subInfo[1] = new Array();
subInfo[2] = new Array();
subInfo[3] = new Array();
subInfo[4] = new Array();
// Set sub's menu's text, links and targets here.
subInfo[2][1] = new Array("Alg. Informatie","Sub-Link 2","");
subInfo[2][2] = new Array("Stadsplattegrond","Link 2","");
subInfo[2][3] = new Array("Links","Sub-Link 1","");
subInfo[2][4] = new Array("Contact","Sub-Link 2","");
subInfo[3][1] = new Array("Stadsdoelen","","");
subInfo[3][2] = new Array("Gemeentebestuur","","");
subInfo[4][1] = new Array("Toneel","","");
subInfo[4][2] = new Array("Beeldkunst","","");
subInfo[4][3] = new Array("Expositie","","");
subInfo[4][4] = new Array("Erfgoed","","");
subInfo[4][5] = new Array("Literatuur","","");
subInfo[4][6] = new Array("Bibliotheken en Archieven","","");
subInfo[4][7] = new Array("Cultuuractief","","");
// Set sub's menu's position (Relative to button)
var xSubOffset = 117;
var ySubOffset = 5;
// No more settings beyond this point.
var overSub = false;
var delay = 1000;
totalButtons = upSources.length;
// Generate the subs and menu.
for (x = 0; x < totalButtons; x++) {
// Set empty div for buttons without submenu.
if (subInfo[x + 1].length < 1) {
document.write('<div id="submenu' + (x + 1) + '">');
// Set div for buttons with submenu.
} else {
document.write('<div id="submenu' + (x + 1) + '" class="dropmenu" ');
document.write('onMouseOver="overSub=true;');
document.write('setOverImg('' + (x + 1) + '','');"');
document.write('onMouseOut="overSub=false;');
document.write('setTimeout(\'hideSubMenu(\'submenu' + (x + 1) + '\')\',delay);');
document.write('setOutImg('' + (x + 1) + '','');">');
document.write('<ul>');
for (k = 0; k < subInfo[x + 1].length-1; k++) {
document.write('<li>');
document.write('<a href="' + subInfo[x + 1][k + 1][1] + '" ');
document.write('target="' + subInfo[x + 1][k + 1][2] + '">');
document.write( subInfo[x + 1][k + 1][0] + '</a>');
document.write('</li>');
}
document.write('</ul>');
}
document.write('</div>');
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> <script type="text/javascript" src="moduleMenu.js"></script> </head> <body> <script type="text/javascript"> var buttonFolder = "buttons"; // Set button's folder here. // Set the button's filenames here. upSources = new Array("button1up.png","button2up.png","button3up.png","button4up.png"); overSources = new Array("button1over.png","button2over.png","button3over.png","button4over.png"); // Sub menu declaration (No modification required) subInfo [1] = new Array(); subInfo [2] = new Array(); subInfo [3] = new Array(); subInfo [4] = new Array(); // Set sub's menu's text, links and targets here. subInfo [2][1] = new Array("Alg. Informatie","Sub-Link 2",""); subInfo [2][2] = new Array("Stadsplattegrond","Link 2",""); subInfo [2][3] = new Array("Links","Sub-Link 1",""); subInfo [2][4] = new Array("Contact","Sub-Link 2",""); subInfo [3][1] = new Array("Stadsdoelen","",""); subInfo [3][2] = new Array("Gemeentebestuur","",""); subInfo [4][1] = new Array("Toneel","",""); subInfo [4][2] = new Array("Beeldkunst","",""); subInfo [4][3] = new Array("Expositie","",""); subInfo [4][4] = new Array("Erfgoed","",""); subInfo [4][5] = new Array("Literatuur","",""); subInfo [4][6] = new Array("Bibliotheken en Archieven","",""); subInfo [4][7] = new Array("Cultuuractief","",""); // Set sub's menu's position (Relative to button) var xSubOffset = 117; var ySubOffset = 5; // No more settings beyond this point. var overSub = false; var delay = 1000; totalButtons = upSources.length; // Generate the subs and menu. for (x = 0; x < totalButtons; x++) { // Set empty div for buttons without submenu. if (subInfo[x + 1].length < 1) { document.write('<div id="submenu' + (x + 1) + '">'); // Set div for buttons with submenu. } else { document.write('<div id="submenu' + (x + 1) + '" class="dropmenu" '); document.write('onMouseOver="overSub=true;'); document.write('setOverImg('' + (x + 1) + '','');"'); document.write('onMouseOut="overSub=false;'); document.write('setTimeout(\'hideSubMenu(\'submenu' + (x + 1) + '\')\',delay);'); document.write('setOutImg('' + (x + 1) + '','');">'); document.write('<ul>'); for (k = 0; k < subInfo[x + 1].length-1; k++) { document.write('<li>'); document.write('<a href="' + subInfo[x + 1][k + 1][1] + '" '); document.write('target="' + subInfo[x + 1][k + 1][2] + '">'); document.write( subInfo[x + 1][k + 1][0] + '</a>'); document.write('</li>'); } document.write('</ul>'); } document.write('</div>'); } </script> </body> </html>
moduleMenu.js
// Main Menu Functions:
// Preload main menu button images.
function preload() {
for (x = 0; x < totalButtons; x++) {
buttonUp = new Image();
buttonUp.src = buttonFolder + upSources[x];
buttonOver = new Image();
buttonOver.src = buttonFolder + overSources[x];
}
}
// Set mouseover button.
function setOverImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + overSources[But - 1];
}
// Set mouseout button.
function setOutImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + upSources[But - 1];
}
// Sub Menu Functions:
// Get element ID multi-browser.
function getElement(id) {
return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null;
}
// Get X coordinate.
function getRealLeft(id) {
var el = getElement(id);
if (el) {
xPos = el.offsetLeft;
tempEl = el.offsetParent;
while (tempEl != null) {
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
}
return xPos;
}
}
// Get Y coordinate.
function getRealTop(id) {
var el = getElement(id);
if (el) {
yPos = el.offsetTop;
tempEl = el.offsetParent;
while (tempEl != null) {
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
}
// Move object to coordinate.
function moveObjectTo(objectID, x, y) {
var el = getElement(objectID);
el.style.left = x;
el.style.top = y;
}
// Move submenu to corresponding button.
function showSubMenu(subID, buttonID) {
hideAllSubMenus();
butX = getRealLeft(buttonID);
butY = getRealTop(buttonID);
moveObjectTo(subID, butX + xSubOffset, butY + ySubOffset);
}
// Hide all submenus.
function hideAllSubMenus() {
for (x = 0; x < totalButtons; x++) {
moveObjectTo("submenu" + (x + 1) + "", -500, -500);
}
}
// Hide one submenu.
function hideSubMenu(subID) {
if ( overSub == false ) {
moveObjectTo(subID, -500, -500);
}
}
// Main Menu Functions: // Preload main menu button images. function preload() { for (x = 0; x < totalButtons; x++) { buttonUp = new Image(); buttonUp.src = buttonFolder + upSources[x]; buttonOver = new Image(); buttonOver.src = buttonFolder + overSources[x]; } } // Set mouseover button. function setOverImg(But, ID) { document.getElementById('button' + But + ID).src = buttonFolder + overSources[But - 1]; } // Set mouseout button. function setOutImg(But, ID) { document.getElementById('button' + But + ID).src = buttonFolder + upSources[But - 1]; } // Sub Menu Functions: // Get element ID multi-browser. function getElement(id) { return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null; } // Get X coordinate. function getRealLeft(id) { var el = getElement(id); if (el) { xPos = el.offsetLeft; tempEl = el.offsetParent; while (tempEl != null) { xPos += tempEl.offsetLeft; tempEl = tempEl.offsetParent; } return xPos; } } // Get Y coordinate. function getRealTop(id) { var el = getElement(id); if (el) { yPos = el.offsetTop; tempEl = el.offsetParent; while (tempEl != null) { yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; } return yPos; } } // Move object to coordinate. function moveObjectTo(objectID, x, y) { var el = getElement(objectID); el.style.left = x; el.style.top = y; } // Move submenu to corresponding button. function showSubMenu(subID, buttonID) { hideAllSubMenus(); butX = getRealLeft(buttonID); butY = getRealTop(buttonID); moveObjectTo(subID, butX + xSubOffset, butY + ySubOffset); } // Hide all submenus. function hideAllSubMenus() { for (x = 0; x < totalButtons; x++) { moveObjectTo("submenu" + (x + 1) + "", -500, -500); } } // Hide one submenu. function hideSubMenu(subID) { if ( overSub == false ) { moveObjectTo(subID, -500, -500); } }
En stylesheet.css is dan dat CSS bestand, als dat erbij zit. Sorry voor XHTML maar dit gebruik ik altijd, naar HTML omzetten is niet echt moeilijk(lees maar bij HTML de tutorial van XHTML dan ken je het verschil). |