Nieuw lid |
|
Hallo allemaal,
Het volgende script (van internet) gebruik ik om menu's open dicht te laten klappen:
function addEvent(obj, type, fn) {
if( obj.attachEvent ) {
obj["e"+type+fn] = fn;
obj[type+fn] = function(){obj["e"+type+fn]( window.event );};
obj.attachEvent( "on"+type, obj[type+fn] );
} else {
obj.addEventListener( type, fn, true );
};
}
function initMenus() {
/*Activate/deactivate menus*/
$$('.smenu').each(function(s,index){
addEvent(s,'click',function(){
if($('smenu'+s.id.replace('a','')).visible()){
//do nothing
} else {
$$('.smenu').each(function(s,index){
if($('smenu'+s.id.replace('a','')).visible()) {
//$('smenu'+s.id).hide(); //Prototype Method
Effect.BlindUp($('smenu'+s.id.replace('a','')), {duration:0.5}); //ScriptAculoUs Method
}
});
//$('smenu'+s.id).show(); //Prototype Method
Effect.BlindDown($('smenu'+s.id.replace('a','')), {duration:0.5}); //ScriptAculoUs Method
}
});
});
/*All menu hiden by default*/
$$('.smenu').each(function(s,index){
if($('smenu'+s.id.replace('a','')).visible()) {
$('smenu'+s.id.replace('a','')).hide();
}
});
/*effects on menu*/
$$('dl#menu dt').each(function(s,index){
addEvent(s,'mouseout',function(){
new Effect.Highlight(s, {duration:0.5, startcolor:'#ed1c22', endcolor:'#ed1c22', restorecolor
:'#ed1c22'});
});
});
}
addEvent(window, 'load', initMenus);
function addEvent(obj, type, fn) { if( obj.attachEvent ) { obj["e"+type+fn] = fn; obj[type+fn] = function(){obj["e"+type+fn]( window.event );}; obj.attachEvent( "on"+type, obj[type+fn] ); } else { obj.addEventListener( type, fn, true ); }; } function initMenus() { /*Activate/deactivate menus*/ $$('.smenu').each(function(s,index){ addEvent(s,'click',function(){ if($('smenu'+s.id.replace('a','')).visible()){ //do nothing } else { $$('.smenu').each(function(s,index){ if($('smenu'+s.id.replace('a','')).visible()) { //$('smenu'+s.id).hide(); //Prototype Method Effect.BlindUp($('smenu'+s.id.replace('a','')), {duration:0.5}); //ScriptAculoUs Method } }); //$('smenu'+s.id).show(); //Prototype Method Effect.BlindDown($('smenu'+s.id.replace('a','')), {duration:0.5}); //ScriptAculoUs Method } }); }); /*All menu hiden by default*/ $$('.smenu').each(function(s,index){ if($('smenu'+s.id.replace('a','')).visible()) { $('smenu'+s.id.replace('a','')).hide(); } }); /*effects on menu*/ $$('dl#menu dt').each(function(s,index){ addEvent(s,'mouseout',function(){ new Effect.Highlight(s, {duration:0.5, startcolor:'#ed1c22', endcolor:'#ed1c22', restorecolor :'#ed1c22'}); }); }); } addEvent(window, 'load', initMenus);
En de html code van het menu zelf:
<dl id="menu">
<dt class="smenu" id="a2"><span>Menu kop</span></dt>
<dd id="smenu1">
<ul>
<li><a href="?pagina=1">1</a></li>
<li><a href="?pagina=2">2</a></li>
<li><a href="?pagina=3">3</a></li>
</ul>
</dd>
</dl>
<li><a href="?pagina=1">1 </a></li> <li><a href="?pagina=2">2 </a></li> <li><a href="?pagina=3">3 </a></li>
Dit script werkt prima. Alleen is er een mogelijkheid om bij het bezoeken van een pagina er voor te zorgen dat het menu uitgeklapt blijft?
Alvast bedankt voor jullie.
|