yourphp.nav.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. var yourphpnav={
  2. buildnav:function($, setting){
  3. var $navobj=$("#"+setting.navid+">ul")
  4. $navobj.parent().get(0).className=setting.classname || "nav"
  5. var $parentobj=$navobj.find("ul").parent()
  6. $parentobj.hover(
  7. function(e){ $(this).children('a:eq(0)').addClass('on') },
  8. function(e){ $(this).children('a:eq(0)').removeClass('on') }
  9. )
  10. $parentobj.each(function(i){
  11. var $obj=$(this).css({zIndex: 999-i})
  12. var $subul=$(this).children('ul:eq(0)')
  13. this.datas={w:this.offsetWidth, h:this.offsetHeight,ulw:$subul.width(), ulh:$subul.height()}
  14. this.istop =$obj.parents("ul").length==1? true : false
  15. $subul.css({top:this.istop && setting.orientation!='v'? this.datas.h+"px" : 0})
  16. $obj.hover(function(e){
  17. var $playobj=$(this).children("ul:eq(0)")
  18. this._offsets={left:$(this).offset().left, top:$(this).offset().top}
  19. var mleft=this.istop && setting.orientation!='v'? 0 : this.datas.ulw
  20. mleft=(this._offsets.left+mleft+this.datas.ulw>$(window).width())? (this.istop && setting.orientation!='v'? -this.datas.ulw+this.datas.w : -this.datas.w) : mleft
  21. $playobj.css({left:mleft+"px", width:this.datas.ulw+'px',display:'block'})
  22. },function(e){
  23. $(this).children("ul:eq(0)").css({display:'none'})
  24. })
  25. });
  26. $navobj.find("ul").css({display:'none', visibility:'visible'})
  27. },
  28. init:function(setting){
  29. jQuery(document).ready(function($){
  30. yourphpnav.buildnav($, setting)
  31. })
  32. }
  33. }