Accordion menu (1k)
Здраствуйте,
Есть горизонтальное меню, в виде слайдеров (accordion), написаное на javascript, вот нашел тут. Хочу использовать его два раза на одной странице с разными настройками. Будет отдельно меню, а под ним отдельно слайды. Хочу использовать именно его, т.к. не требует дополнительных библиотек, и все работает и грузит достаточно шустро. Код страницы: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> <script type="text/javascript" src="files/slidemenu.js"></script> <style type="text/css"> .sm {width:900px; height:100px; display:block; overflow:hidden;} .sm li {float:left; display:inline; overflow:hidden; background-image: url(files/img/menu.gif); width: 900px; height: 55px;} </style> </head> <body onload="slideMenu.build('sm',700,10,10,1)"> <ul id="sm" class="sm"> <li><div id="menu1"></div></li> <li><div id="menu2"></div></li> <li><div id="menu3"></div></li> </ul> </body> </html> javascript: var slideMenu=function(){ var sp,st,t,m,sa,l,w,sw,ot; return{ build:function(sm,sw,mt,s,sl,h){ sp=s; st=sw; t=mt; m=document.getElementById(sm); sa=m.getElementsByTagName('li'); l=sa.length; w=m.offsetWidth; sw=w/l; ot=Math.floor((w-st)/(l-1)); var i=0; for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)} if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)} }, timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}}, slide:function(s){ var cw=parseInt(s.style.width,'10'); if(cw<st){ var owt=0; var i=0; for(i;i<l;i++){ if(sa[i]!=s){ var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10'); if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'} owt=owt+(ow-oi)}} s.style.width=(w-owt)+'px'; }else{clearInterval(m.timer)} } }; }(); Если просто добавить: <style type="text/css"> .sm {width:900px; height:55px; display:block; overflow:hidden;} .sm li {float:left; display:inline; overflow:hidden; background-image: url(files/img/menu.gif); width: 900px; height: 55px;} .ag {width:600px; height:400px; display:block; overflow:hidden;} .ag li {float:left; display:inline; overflow:hidden; background-image: url(files/img/slide.gif); width: 600px; height: 400px;} </style> А в <body> дописать: body onload="slideMenu.build('sm',700,10,10,1);slideMenu.build('ag',700,10,10,1)"> и <ul id="sm" class="sm"> <li><div id="menu1"></div></li> <li><div id="menu2"></div></li> <li><div id="menu3"></div></li> </ul> <ul id="ag" class="ag"> <li><div id="menu1"></div></li> <li><div id="menu2"></div></li> <li><div id="menu3"></div></li> </ul> Результата нет( Дело в самом скрипте, но не могу понять что там не так. Что где подправить? P.S. На сайте, по ссылке, на одной странице 2 меню, но первое через iframe. Это не то. |
Помогите кто-нибудь. Проект горит, все готово, а вот этот вопрос до сих пор открыт.
|
Constantin.UK,
сделайте дубликат функции slideMenu и запускайте его с новыми параметрами |
Цитата:
|
Constantin.UK,
Алгоритм дубляжа: найдите функцию slideMenu поменяйте её название, посмотрите нет ли внутри функции ссылок на саму себя и замените на это же название - и того 1 копи паст функции и три раза нажата циферка 2 для примера Если снова не получилось глянуть код ниже ... скрипт зависит от настроек css и не ставьте div в li без особой нужды <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> var slideMenu=function(){ var sp,st,t,m,sa,l,w,sw,ot; return{ build:function(sm,sw,mt,s,sl,h){ sp=s; st=sw; t=mt; m=document.getElementById(sm); sa=m.getElementsByTagName('li'); l=sa.length; w=m.offsetWidth; sw=w/l; ot=Math.floor((w-st)/(l-1)); var i=0; for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)} if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t)} }, timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu.slide(s)},t)}}, slide:function(s){ var cw=parseInt(s.style.width,'10'); if(cw<st){ var owt=0; var i=0; for(i;i<l;i++){ if(sa[i]!=s){ var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10'); if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'} owt=owt+(ow-oi)}} s.style.width=(w-owt)+'px'; }else{clearInterval(m.timer)} } }; }(); var slideMenu2=function(){ var sp,st,t,m,sa,l,w,sw,ot; return{ build:function(sm,sw,mt,s,sl,h){ sp=s; st=sw; t=mt; m=document.getElementById(sm); sa=m.getElementsByTagName('li'); l=sa.length; w=m.offsetWidth; sw=w/l; ot=Math.floor((w-st)/(l-1)); var i=0; for(i;i<l;i++){s=sa[i]; s.style.width=sw+'px'; this.timer(s)} if(sl!=null){m.timer=setInterval(function(){slideMenu2.slide(sa[sl-1])},t)} }, timer:function(s){s.onmouseover=function(){clearInterval(m.timer);m.timer=setInterval(function(){slideMenu2.slide(s)},t)}}, slide:function(s){ var cw=parseInt(s.style.width,'10'); if(cw<st){ var owt=0; var i=0; for(i;i<l;i++){ if(sa[i]!=s){ var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width,'10'); if(ow>ot){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'} owt=owt+(ow-oi)}} s.style.width=(w-owt)+'px'; }else{clearInterval(m.timer)} } }; }(); </script> <style type="text/css"> * {margin:0; padding:0} .sm {list-style:none; width:500px; height:100px; display:block; overflow:hidden} .sm li {float:left; display:inline; overflow:hidden; width: 200px; height: 80px;} .ag {list-style:none; width:500px; height:100px; display:block; overflow:hidden} .ag li {float:left; display:inline; overflow:hidden; width: 200px; height: 80px;} </style> </head> <body onload="slideMenu.build('sm',336,10,10,1);slideMenu2.build('ag',336,10,10,1)"> <ul id="sm" class="sm"> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> </ul> <ul id="ag" class="ag"> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> <li><img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" alt="" /></li> </ul> </body> </html> |
Часовой пояс GMT +3, время: 07:03. |