as實現css風格菜單

來源:互聯網
上載者:User
 

var navArray = ["簡歷","作品展示","學習中心","聯絡我吧","友情連結"]
// correct colors in menu
function setupMenu () {
 
 // colors
 BaseColor = 0x414042;
 RolloverColor = 0xCCC2C0;
 SelectedColor = 0xF15B40;
 
 // buttons
 for (var i=1; i<=5; ++i) {
  // assign item id
  nav_menu["item_"+i].num = i;
  
  nav_menu["item_"+i]._txt.text = navArray[i-1];
  nav_menu["item_"+i].hit_btn._width = nav_menu["item_"+i]._txt.textWidth+5;
  // Set original Color
  var c = new Color(nav_menu["item_"+i]);
  c.setRGB(BaseColor);
  
  // Set RollOver color state for all buttons
  nav_menu["item_"+i].onRollOver =function  () {
   var c = new Color(this);
   c.setRGB(RolloverColor);
  }
  
  // Set RollOut color state for all buttons
  nav_menu["item_"+i].onRollOut =nav_menu["item_"+i].onReleaseOutside = function  () {
   var c = new Color(this);
   c.setRGB(BaseColor);
  }
  
  // Set Click color state for all buttons
  nav_menu["item_"+i].onRelease = function  () {
   // call switch function
   switchActiveColor(this.num);
  }
  
  
 }
}

// navigation
function switchActiveColor(num) {
 // Set current selection
 currentSelection = num;
 // ALl buttons
 for (var i=1; i<=5; ++i) {
  nav_menu["item_"+i].enabled = true;
  var c = new Color(nav_menu["item_"+i]);
  c.setRGB(BaseColor);
  if (i==num) {
   nav_menu["item_"+i].enabled = false;
   c.setRGB(SelectedColor);
  }
 }
}

setupMenu();

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.