蜂巢式導航選單程式碼例項

antzone發表於2017-04-18

分享一段程式碼例項,它實現了類似蜂巢式導航選單。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
.Ct {
  width: 1000px;
  margin: 0 auto;
}
.ywPart1 {
  width: 310px;
  margin: 0 auto;
  padding: 20px 10px 20px 30px;
}
/**蜂巢樣式***/
.hex {
  float: left;
  margin-left: 2px;
  margin-bottom: -18px;
  cursor: pointer;
}
.hex .hex_top {
  width: 0;
  border-bottom: 20px solid #f0f0f0;
  border-left: 35px solid transparent;
  border-right: 35px solid transparent;
  margin-top: -1px\9 \0;
  margin-top: 0px\0;
}
.hex .hex_middle {
  width: 70px;
  height: 30px;
  line-height: 30px;
  background: #f0f0f0;
  text-align: center;
  font-family: "宋體";
  color: #333333;
}
.hex .hex_bottom {
  width: 0;
  border-top: 20px solid #f0f0f0;
  border-left: 35px solid transparent;
  border-right: 35px solid transparent;
  margin-top: -1px\9 \0;
  margin-top: 0px\0;
}
.hex-row {
  clear: left;
}
.hex-row.even {
  margin-left: 38px;
}
.hex-row.odd {
  margin-right: 38px;
}
.hex.hexActive .hex_top {
  width: 0;
  border-bottom: 20px solid #86ccac;
  border-left: 35px solid transparent;
  border-right: 35px solid transparent;
  margin-top: -1px\9 \0;
  margin-top: 0px\0;
}
.hex.hexActive .hex_middle {
  width: 70px;
  height: 30px;
  line-height: 30px;
  background: #86ccac;
  text-align: center;
  font-family: "宋體";
  color: #FFFFFF;
}
.hex.hexActive .hex_bottom {
  width: 0;
  border-top: 20px solid #86ccac;
  border-left: 35px solid transparent;
  border-right: 35px solid transparent;
  margin-top: -1px\9 \0;
  margin-top: 0px\0;
}
</style>
</head>
<body>
  <div class="Ct">
    <div class="ywPart1" id="hexDiv">
      <div class="hex hexActive" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">即時通訊</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">閱讀</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">微博</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">導航</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex hex-row even" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">視訊</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">音樂</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">應用商店</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex hex-row" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">遊戲</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">支付</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">動漫</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">P2P業務</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex hex-row even" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">VOIP業務</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">彩信</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">瀏覽下載</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex hex-row" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">財經</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">安全防毒</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">郵箱</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="hex" name="hexBlcok">
        <div class="hex_top"></div>
        <div class="hex_middle">其他</div>
        <div class="hex_bottom"></div>
      </div>
      <div class="ClearFloat"></div>
    </div>
  </div>
  <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
  <script>
  $("#hexDiv").find("div[name='hexBlcok']").on("click",function(){
    $(this).addClass("hexActive");
    $(this).siblings("div[name='hexBlcok']").removeClass("hexActive");
  });
  </script>
</body>
</html>

相關文章