您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • 当前位置:首页 > 网页特效 > 导航菜单 >

    竖向折叠的CSS滑动菜单

    时间:2014-06-11 08:24 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印
    运行代码保存代码复制代码 提示:您可以先修改部分代码再运行,保存代码功能在Firefox下无效。
    • 折叠菜单,竖向展开,点击时缓慢展开,展开后可以作为菜单的栏目介绍等,还算不错。
    • <script type="text/javascript">
      //<![CDATA[
      window.onload = function() {
      rolinTab("rolin")
      }
      function rolinTab(obj) {
      var list = $(obj).getElementsByTagName("LI");
      var state = {show:false,hidden:false,showObj:false};
      for (var i=0; i<list.length; i++) {
      var tmp = new rolinItem(list[i],state);
      if (i == 0) tmp.pShow();
      }
      }
      function rolinItem(obj,state) {
      var speed = 0.0666;
      var range = 1;
      var interval;
      var tarH;
      var tar = this;
      var head = getFirstChild(obj);
      var content = getNextChild(head);
      var isOpen = false;
      this.pHidden = function() {
      if (isOpen) hidden();
      }
      this.pShow = show;
      var baseH = content.offsetHeight;
      content.style.display = "none";
      var isOpen = false;
      head.onmouseover = function() {
      this.style.background = "#EFEFEF";
      }
      head.onmouseout = mouseout;
      head.onclick = function() {
      this.style.background = "#EFEFEF";
      if (!state.show && !state.hidden) {
      if (!isOpen) {
      head.onmouseout = null;
      show();
      } else {
      hidden();
      }
      }
      }
      function mouseout() {
      this.style.background = "#FFF"
      }
      function show() {
      head.style.borderBottom = "1px solid #DADADA";
      state.show = true;
      if (state.openObj && state.openObj != tar ) {
      state.openObj.pHidden();
      }
      content.style.height = "0px";
      content.style.display = "block";
      content.style.overflow = "hidden";
      state.openObj = tar;
      tarH = baseH;
      interval = setInterval(move,10);
      }
      function showS() {
      isOpen = true;
      state.show = false;
      }
      function hidden() {
      state.hidden = true;
      tarH = 0;
      interval = setInterval(move,10);
      }
      function hiddenS() {
      head.style.borderBottom = "none";
      head.onmouseout = mouseout;
      head.onmouseout();
      content.style.display = "none";
      isOpen = false;
      state.hidden = false;
      }
      function move() {
      var dist = (tarH - content.style.height.pxToNum())*speed;
      if (Math.abs(dist) < 1) dist = dist > 0 ? 1: -1;
      content.style.height = (content.style.height.pxToNum() + dist) + "px";
      if (Math.abs(content.style.height.pxToNum() - tarH) <= range ) {
      clearInterval(interval);
      content.style.height = tarH + "px";
      if (tarH != 0) {
      showS()
      } else {
      hiddenS();
      }
      }
      }
      }
      var $ = function($) {return document.getElementById($)};
      String.prototype.pxToNum = function() {return Number(this.replace("px",""))}
      function getFirstChild(obj) {
      var result = obj.firstChild;
      while (!result.tagName) {
      result = result.nextSibling;
      }
      return result;
      }
      function getNextChild(obj) {
      var result = obj.nextSibling;
      while (!result.tagName) {
      result = result.nextSibling;
      }
      return result;
      }
      //]]>
      </script>
    竖向折叠的CSS滑动菜单由源码搜藏网整理,转载请注明出处http://www.codesocang.com/texiao/daohang/9083.html
    标签:网站源码