dedecms做下拉菜单:
将下面这段代码贴到templets\default\footer.htm文件里
<!-- //二级子类下拉菜单,考虑seo原因放置于底部 --> <script type='text/javascript' src='{dede:global.cfg_cmsurl/}/images/js/dropdown.js'></script> {dede:channelartlist typeid='top' cacheid='channelsonlist'} <ul id="dropmenu{dede:field.typeid/}" class="dropmenu"> {dede:channel type='son' noself='yes'} <li><a href="[field:typelink/]">[field:typename/]</a></li> {/dede:channel} </ul> {/dede:channelartlist} <script type="text/javascript">cssdropdown.startchrome("navmenu")</script>
以上代码可以看出,二级子类下拉菜单是由dropdown.js控制的,我们来看dropdown.js文件:
由以上的cssdropdown.startchrome("navmenu"),可以看出我们调用的是 startchrome:function()
var cssdropdown={disappeardelay: 250, disablemenuclick: false, enableswipe: 1, enableiframeshim: 1, dropmenuobj: null, ie: document.all, firefox: document.getelementbyid&&!document.all, swipetimer: undefined, bottomclip:0, getposoffset:function(what, offsettype){var totaloffset=(offsettype=="left")? what.offsetleft : what.offsettop;var parentel=what.offsetparent;while (parentel!=null){totaloffset=(offsettype=="left")? totaloffset+parentel.offsetleft : totaloffset+parentel.offsettop;parentel=parentel.offsetparent;}return totaloffset;}, swipeeffect:function(){if (this.bottomclip<parseint(this.dropmenuobj.offsetheight)){this.bottomclip+=10+(this.bottomclip/10) this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"}elsereturnthis.swipetimer=settimeout("cssdropdown.swipeeffect()", 10)}, showhide:function(obj, e){if (this.ie || this.firefox)this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){if (this.enableswipe==1){if (typeof this.swipetimer!="undefined")cleartimeout(this.swipetimer)obj.clip="rect(0 auto 0 0)" this.bottomclip=0this.swipeeffect()}obj.visibility="visible"}else if (e.type=="click")obj.visibility="hidden"}, iecompattest:function(){return (document.compatmode && document.compatmode!="backcompat")? document.documentelement : document.body}, clearbrowseredge:function(obj, whichedge){var edgeoffset=0if (whichedge=="rightedge"){var windowedge=this.ie && !window.opera? this.iecompattest().scrollleft+this.iecompattest().clientwidth-15 : window.pagexoffset+window.innerwidth-15this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetwidthif (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure) edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetwidth}else{var topedge=this.ie && !window.opera? this.iecompattest().scrolltop : window.pageyoffsetvar windowedge=this.ie && !window.opera? this.iecompattest().scrolltop+this.iecompattest().clientheight-15 : window.pageyoffset+window.innerheight-18this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetheightif (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){ edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetheightif ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure) edgeoffset=this.dropmenuobj.y+obj.offsetheight-topedge}}return edgeoffset}, dropit:function(obj, e, dropmenuid){if (this.dropmenuobj!=null) this.dropmenuobj.style.visibility="hidden" this.clearhidemenu()if (this.ie||this.firefox){obj.οnmοuseοut=function(){cssdropdown.delayhidemenu()}obj.οnclick=function(){return !cssdropdown.disablemenuclick} this.dropmenuobj=document.getelementbyid(dropmenuid)if(!this.dropmenuobj) return;this.dropmenuobj.οnmοuseοver=function(){cssdropdown.clearhidemenu()}this.dropmenuobj.οnmοuseοut=function(e){cssdropdown.dynamichide(e)}this.dropmenuobj.οnclick=function(){cssdropdown.delayhidemenu()}this.showhide(this.dropmenuobj.style, e)this.dropmenuobj.x=this.getposoffset(obj, "left")this.dropmenuobj.y=this.getposoffset(obj, "top")this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetheight+1+"px"this.positionshim() }}, positionshim:function(){ if (this.enableiframeshim && typeof this.shimobject!="undefined"){if (this.dropmenuobj.style.visibility=="visible"){this.shimobject.style.width=this.dropmenuobj.offsetwidth+"px"this.shimobject.style.height=this.dropmenuobj.offsetheight+"px"this.shimobject.style.left=this.dropmenuobj.style.leftthis.shimobject.style.top=this.dropmenuobj.style.top}this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"}}, hideshim:function(){if (this.enableiframeshim && typeof this.shimobject!="undefined")this.shimobject.style.display='none'}, contains_firefox:function(a, b) {while (b.parentnode)if ((b = b.parentnode) == a)return true;return false;}, dynamichide:function(e){var evtobj=window.event? window.event : eif (this.ie&&!this.dropmenuobj.contains(evtobj.toelement))this.delayhidemenu()else if (this.firefox&&e.currenttarget!= evtobj.relatedtarget&& !this.contains_firefox(evtobj.currenttarget, evtobj.relatedtarget))this.delayhidemenu()}, delayhidemenu:function(){this.delayhide=settimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; cssdropdown.hideshim()",this.disappeardelay) }, clearhidemenu:function(){if (this.delayhide!="undefined")cleartimeout(this.delayhide)}, startchrome:function(){for (var ids=0; ids<arguments.length; ids++){var menuitems=document.getelementbyid(arguments[ids]).getelementsbytagname("a")for (var i=0; i<menuitems.length; i++){if (menuitems[i].getattribute("rel")){var relvalue=menuitems[i].getattribute("rel")menuitems[i].οnmοuseοver=function(e){var event=typeof e!="undefined"? e : window.eventcssdropdown.dropit(this,event,this.getattribute("rel"))}}}}if (window.createpopup && !window.xmlhttprequest){ document.write('<iframe id="iframeshim" src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:dximagetransform.microsoft.alpha(style=0,opacity=0)" frameborder="0" scrolling="no"></iframe>')this.shimobject=document.getelementbyid("iframeshim") }}}
由上可以看出,var cssdropdown变量中有多个函数:
getposoffset:function(what, offsettype)swipeeffect:function()showhide:function(obj, e) iecompattest:function()clearbrowseredge:function(obj, whichedge)dropit:function(obj, e, dropmenuid)positionshim:function()hideshim:function()dynamichide:function(e)delayhidemenu:function()clearhidemenu:function()startchrome:function()
更新一下!会发现导航栏已经出现下拉菜单了,只是背景是透明的,原因是没有背景图片。
然后我们可以对此下拉菜单添加背景图片和设置css样式。
推荐:dedecms使用教程
以上就是dedecms怎么做下拉菜单的详细内容。