zoukankan      html  css  js  c++  java
  • 左侧分类导航菜单(续)

    左侧分类导航菜单,是电商购物导航的最直接的分类形式。

    js方面主要以下几点注意
    1、事件有mouseover、mouseleave
    onmouseover 事件会在鼠标指针移动到指定的对象上时发生。
    onmouseleave 事件会在鼠标指针移出到指定的对象时发生。
    2、setTimeout、clearTimeout
    setTimeout 方法用于在指定的毫秒数后调用函数或计算表达式。setTimeout() 只执行 code 一次。
    clearTimeout 方法可取消由 setTimeout() 方法设置的 timeout。

    代码片段:
    鼠标移动到li元素上和移出元素时执行的动作

    _this.showlist.find(".item").live("mouseover",function(){
        var $this = $(this), show = _this.showlist.find(".show"), len = show.length;
        
        if(!!stopOver){
            clearTimeout(stopOver);
        }
        if(!!stopLeave){
            clearTimeout(stopLeave);
        }
        stopOver =  setTimeout(function(){
            _this.showlist.find(".show,.tri").hide();
            _this.showlist.find(".tit").removeClass("on");
    
            var index = $this.index(),tmpheight = $this.find(".show").height(),topval = 0;
    
            if(index < 5){
                topval = index * (-41);
                show.css({"top": topval + "px"});
            } else if(index > ( len - 5)) {
                topval = -tmpheight + (len - 1 -index) * 41 + 20;
                show.css({"top": topval + "px"});
            } else{
                var tmpheight = $this.find(".show").height();
                topval = -tmpheight/2 + 10;
                show.css({"top": topval + "px"});
            }
            
            $this.find(".show,.tri").show();
            $this.find(".tit").addClass("on");
        },_this.params.delay);
    });
    
    _this.showlist.find(".item").live("mouseleave",function(){
        var $this = $(this);
        stopLeave = setTimeout(function(){
            $this.find(".show,.tri").hide();
            $this.find(".tit").removeClass("on");
        },_this.params.delay);
    });


    css方面主要一下几点注意
    1、position: relative 和 position的使用
    2、清楚浮动
    3、hover伪类的使用


    代码演示:

    如果设置显示将"navSwitch": "navopen",默认隐藏。

    默认效果如下:

  • 相关阅读:
    Java 注解
    java 编码设计细节
    快捷键大全
    java 常用方法
    用SelectSingleNode()方法查找xml节点一直返回null
    未能加载文件或程序集“microsoft.Build.Engine, Version=3.5.0.0,...”或它的摸一个依赖项。
    引用dll出现了黄色感叹号
    保持控件和容器之间的相对位置
    DataGridView中EnditCommit()调用之后,单元格的内容被全选了,每次输入都要鼠标点击定位到最后才能继续输入
    访问DataGridView的Rows报了OutOfIndexRangeException错误
  • 原文地址:https://www.cnblogs.com/kuikui/p/3237190.html
Copyright © 2011-2022 走看看