Web前端之jQuery

一、 寻找元素(重要的选择器和筛选器)

基本语法:$(selector).action()                   

2.1   选择器

    2.1.1 基本选择器      $("*")  $("#id")   $(".class")  $("element")  $(".class,p,div")

    2.1.2层级选择器       $(".outer div")  $(".outer>div")   $(".outer+div")  $(".outer~div")

    2.1.3 基本筛选器      $("li:first")  $("li:eq(2)")  $("li:even") $("li:gt(1)")

    2.1.4 属性选择器      $(‘[id="div1"]‘)   $(‘["alex="sb"][id]‘)

    2.1.5 表单选择器      $("[type=‘text‘]")----->$(":text")                    注意只适用于input标签

                                 $("input:checked")

2.2 筛选器

  2.2.1  过滤筛选器

                                     $("li").eq(2)  $("li").first()  $("ul li").hasclass("test")

     2.2.2  查找筛选器

                                $("div").children(".test")    $("div").find(".test")  

                                $(".test").next()    $(".test").nextAll()   $(".test").nextUntil()

                                $("div").prev()  $("div").prevAll()  $("div").prevUntil()

                                $(".test").parent()  $(".test").parents()  $(".test").parentUntil() 

                                $("div").siblings()

实例 左侧菜单 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.12.4.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .title{
            background-color: #1a386a;
            color: white;;
            cursor: pointer;
        }
        .menu {
            background-color: grey;
            width: 20%;
            float: left;
            height: 500px;
            line-height: 40px;
        }
        .content {
            width: 80%;
            float: left;
            background-color: #6cd9c9;
            height: 500px;
        }
        .hide {
            display: none;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="menu">
            <div class="item">
                <div class="title">菜单一</div>
                <div class="con">
                    <div>111</div>
                    <div>111</div>
                    <div>111</div>
                </div>
            </div>
            <div class="item">
                <div class="title">菜单二</div>
                <div class="con hide">
                    <div>111</div>
                    <div>111</div>
                    <div>111</div>
                </div>
            </div>
            <div class="item">
                <div class="title">菜单三</div>
                <div class="con hide">
                    <div>111</div>
                    <div>111</div>
                    <div>111</div>
                </div>
            </div>
            <div class="item">
                <div class="title">菜单四</div>
                <div class="con hide">
                    <div>111</div>
                    <div>111</div>
                    <div>111</div>
                </div>
            </div>
        </div>
        <div class="content"></div>
    </div>

    <script>
        $(document).ready(function () {
            $(".title").click(function () {
             $(".title").next().addClass("hide")
                $(this).next().removeClass("hide")
            })
        })
    </script>
</body>
</html>

实例 tab切换

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>tab</title>
    <script src="jquery-1.12.4.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .outer {
            width: 500px;
            margin: 0 auto;
            background-color: #333333;
            color: white;
        }

        .outer li {
            display: inline-block;
            list-style: none;
            line-height: 50px;
            width: 80px;
            text-align: center;

        }
        .inner{
            height: 300px;
            background-color: #139412;
            border: 1px solid transparent;

        }
        .hide {
            display: none;
        }
        .current{
            background-color: #f42760;
            color: black;
            border: solid 2px transparent;
        }
    </style>
</head>
<body>
    <div class="outer">
        <ul>
            <li class="current" conctent="c1">菜单一</li>
            <li conctent="c2">菜单二</li>
            <li conctent="c3">菜单三</li>
        </ul>
        <div class="inner">
            <div text_con="c1">我是内容一</div>
            <div text_con="c2" class="hide">我是内容二</div>
            <div text_con="c3" class="hide">我是内容三</div>
        </div>
    </div>
    <script>
        $("li").click(function () {
            $(this).addClass("current").siblings().removeClass("current");
            $("[text_con="+$(this).attr(‘conctent‘)+"]").removeClass("hide").siblings().addClass("hide");

        })

    </script>
</body>
</html>

二、 操作元素(属性 CSS 和 文档处理)

2.1 属性操作

     $("p").text()    $("p").html()   $(":checkbox").val()  

      $(".test").attr("alex")   $(".test").attr("al","sb") 

      $(".test").attr("checked","checked")  $(":checkbox").removeAttr("checked")

      $(".test").prop("checked",true)

      $(".test").addClass("hide")

实例 编辑框正反选

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.12.4.js"></script>
</head>
<body>
    <div>
        <input class="selA" type="button" value="全选"/>
        <input class="selB" type="button" value="取消"/>
        <input class="selC" type="button" value="反选"/>
    </div>
    <table>
        <thead>
            <th>序号</th>
            <th> 姓名</th>
            <th> 年龄</th>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox"/></td>
                <td>a</td>
                <td>18</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>b</td>
                <td>19</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>c</td>
                <td>20</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>d</td>
                <td>21</td>

            </tr>

        </tbody>
        <script>
        $(".selA").click(function () {

            $(":input").prop("checked",true);
        })
        $(".selB").click(function () {
            $(":input").prop("checked",false);
        })
        $(".selC").click(function () {
            $("table :input").each(function () {
                if ($(this).prop("checked")){
                    $(this).prop("checked",false);
                }else{
                     $(this).prop("checked",true);
                }
            })
        })

        </script>
    </table>
</body>
</html>

jQuery里each循环原理

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.12.4.js"></script>
</head>
<body>
    <script>
        function myeach(obj,func) {
            for(var i = 0;i<obj.length;i++){
                var current = obj[i];
                var ret = func(i,current);
                if(ret == "false"){
                    break
                }
            }
        }
         var li = [11,22,33];
            myeach(li,function (k,v) {
                console.log(k,v);
                return false;
            })
        $.each()
    </script>
</body>
</html>

2.2 CSS操作

3.2.1(样式)   css("{color:‘red‘,backgroud:‘blue‘}") 

        3.2.2(位置)   offset()    position()  scrollTop()  scrollLeft()    

        3.2.3(尺寸)   height()  width()  

实例 返回顶部

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.12.4.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .menu{
            height: 5000px;
            background-color: #99aecb;
        }
        h1{
            text-align: center;
            line-height: 90px;

        }
        .returnTop{
            position: fixed;
            right: 20px;
            bottom: 20px;
            width: 38px;
            height: 38px;
            background-color: #f42760;
            font-size: 14px;
            text-align: center;
            font-family: "微软雅黑";
        }
        .hide {
            display: none;
        }
    </style>
</head>
<body>
    <div class="menu">
        <h1>我是第一行</h1>
    </div>
    <div class="returnTop hide">返回顶部</div>
    <script>
        window.onscroll=function () {
            var current = $(window).scrollTop();
            if (current>100){
                $(".returnTop").removeClass("hide");
            }else{
                $(".returnTop").addClass("hide");
            }
        }
        $(".returnTop").click(function () {
            $(window).scrollTop(0)
            }
        )

    </script>
</body>
</html>

实例 滚动菜单 

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="jquery-1.12.4.js"></script>
    <style>
        body,img,ul {
            margin: 0;
            padding:0;
            list-style: none;
            border: 0;
        }
        .pg-header {
            background-color: #35536D;
        }
        .warp {
            width: 980px;
            margin: 0 auto;
        }
        .clearfix:after {
            content: ".";
            display: block;
            clear: both;
            height: 0 ;
            visibility: hidden;
        }
        .pg-header .logo   {
            float: left;
            padding: 5px 10px 5px 0px;
        }
        .pg-header .logo img {
            width: 110px;
            height: 40px;
        }
        .pg-header .nav ul li {
            float: left;

        }
        .pg-header .nav ul li a {
            display: block;
            text-decoration: none;
            color: #ccc;
            font-size: 16px;
            line-height: 50px ;
            font-family: "微软雅黑";
            padding: 0 20px ;
        }
        .pg-header .nav ul li a:hover{
            color: #fff;
            background-color: #1864aa;
        }
        .pg-body .catalog {
            position: absolute;
            top: 60px;
            width: 200px;
            background-color: #fafafa;
            border: 0px;
        }
        .pg-body .catalog.fixed{
            position: fixed;
            top:10px;
        }
        .pg-body .catalog .catalog-item{
            background-color: #fafafa;
        }
        .pg-body .content {
            position: absolute;
            top: 60px;
            width:700px;
            margin-left: 210px;
            background-color: #fafafa;
            overflow: auto;
        }
        .pg-body .content .section{
            height: 500px;
        }
    </style>
<html>
<body>
    <div class="pg-header">
        <div class="warp clearfix">
            <div class="logo">
                <a href="javascript:void (0)"><img src="3.png"/></a>
            </div>
            <div class="nav">
                <ul>
                    <li><a href="javascript:void(0)">首页</a></li>
                    <li><a href="javascript:void(0)">菜单一</a></li>
                    <li><a href="javascript:void(0)">菜单二</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="pg-body">
        <div class="warp">
            <div class="catalog">
                <div class="catalog-item"auto-to="function1"><a>第一页</a></div>
                <div class="catalog-item"auto-to="function2"><a>第二页</a></div>
                <div class="catalog-item"auto-to="function3"><a>第三页</a></div>
            </div>
            <div class="content">
                <div menu="function1"class="section"><h1>第一章</h1></div>
                <div menu="function2"class="section"><h1>第二章</h1></div>
                <div menu="function3"class="section"><h1>第三章</h1></div>
            </div>
        </div>
    </div>
    <script>
        window.onscroll=function () {
            var ws = $(window).scrollTop();
            if (ws >60){
                $(".catalog").addClass("fixed");
            }else{
                $(".catalog").removeClass("fixed");
            }
            if ($(document).height()==$(window).height()+ws){
                $(".catalog").children(":last").css("fontSize","40px").siblings().css("fontSize","16px");
                return;
            }
            $(".content").children().each(function () {
                var offset=$(this).offset().top;
                var total = $(this).height()+ offset;
                if (ws >offset && ws < total){
                    var index=$(this).attr("menu");
                    var new_inde="[auto-to="+index+"]";
                    $(new_inde).css("fontSize","40px").siblings().css("fontSize","15px");
                }
            })

        }
    </script>
</body>
</html>

2.3 文档处理

内部插入  $("#c1").append("<b>hello</b>")     $("p").appendTo("div")

                   prepend()    prependTo()

外部插入  before()  insertBefore()  after insertAfter()

                     replaceWith()   remove()  empty()  clone()

2.4 事件

2.4.1

               $(document).ready(function(){}) -----------> $(function(){})

2.4.2

               $("p").click(function(){})

               $("p").bind("click",function(){})                    

               $("ul").delegate("li","click",function(){})

实例 拖动面板

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div style="border: 1px solid #ddd;width: 600px;position: absolute;">
        <div id="title" style="background-color: black;height: 40px;color: white;">
            标题
        </div>
        <div style="height: 300px;">
            内容
        </div>
    </div>
<script type="text/javascript" src="jquery-2.2.3.js"></script>
<script>
    $(function(){
        // 页面加载完成之后自动执行
        $(‘#title‘).mouseover(function(){
            $(this).css(‘cursor‘,‘move‘);
        }).mousedown(function(e){
            //console.log($(this).offset());
            var _event = e || window.event;
            // 原始鼠标横纵坐标位置
            var ord_x = _event.clientX;
            var ord_y = _event.clientY;

            var parent_left = $(this).parent().offset().left;
            var parent_top = $(this).parent().offset().top;

            $(this).bind(‘mousemove‘, function(e){
                var _new_event = e || window.event;
                var new_x = _new_event.clientX;
                var new_y = _new_event.clientY;

                var x = parent_left + (new_x - ord_x);
                var y = parent_top + (new_y - ord_y);

                $(this).parent().css(‘left‘,x+‘px‘);
                $(this).parent().css(‘top‘,y+‘px‘);

            })
        }).mouseup(function(){
            $(this).unbind(‘mousemove‘);
        });
    })
</script>
</body>
</html>

实现鼠标拖动内容框

<!DOCTYPE html>

<html>
    <head>
        <meta charset="utf-8">
        <title>Index</title>
        <style>
            a {
                color: #428bca;
                text-decoration: none;
                }

                .modal-backdrop {
                  position: fixed;
                  top: 0;
                  right: 0;
                  bottom: 0;
                  left: 0;
                  z-index: 1050;
                  background-color: #white;
                  opacity: 0.8;
                }

                .modal {
                  position: fixed;
                  top: 30%;
                  left: 50%;
                  z-index: 1030;
                }

                .hide {
                    display:none;
                }
        </style>
    </head>
    <body>
        <div>
            <input type="button" onclick="fadeIn();"  value="加载条"/>
        </div>
        <div id="shade" class="modal-backdrop hide">
            <div  class="modal">
                <img src="./images/loading_32.gif"/>
            </div>
        </div>
        <script >
            function fadeIn() {
                document.getElementById(‘shade‘).className = ‘modal-backdrop‘;
            }

            function fadeOut() {
                document.getElementById(‘shade‘).className = ‘modal-backdrop hide‘;
            }
        </script>
    </body>
</html>

实例:加载

加载条

/*公共开始*/
body {
    margin: 0 auto;
    font-family: Arial;
    _font-family: 宋体,Arial;
    font-size: 12px;
}
body, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td, figure, div {
    margin: 0;
    padding: 0;
}

ol, ul, li {
    list-style: none;
}
a{
    cursor:pointer;
    text-decoration:none;
}
/*a:hover{
    color: #F60 !important;
    text-decoration: underline;
}*/
img{
    border:none;
    border-width:0px;
}
table{
    border-collapse: collapse;
    border-spacing: 0;
}

.red{
    color: #c00!important;
}
.m8{
    margin:8px;
}
.mt10{
    margin-top:10px;
}
.mt20{
    margin-top:20px;
}
.mr5{
    margin-right:5px;
}
.ml5{
    margin-left:5px;
}

.ml10{
    margin-left:10px;
}

.mb10{
    margin-bottom:10px;
}
.pt18{
    padding-top:18px;
}
.pt20{
    padding-top:20px;
}
.pb20{
    padding-bottom:20px;
}
.nbr{
    border-right:0px;
}
.font12{
    font-size:12px;
}
.font14{
    font-size:14px;
}
.font16{
    font-size:16px;
}
.bold{
    font-weight:bold;
}
.left{
    float:left;
}
.right{
    float:right;
}
.hide{
    display:none;
}
.show{
     display:table;
}
.clearfix{
    clear:both;
}
.clearfix:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
* html .clearfix {zoom: 1;}

.container{
    width:1190px;
    margin-left:auto;
    margin-right:auto;

}

.group-box-1 .title{
    height: 33px;
    line-height: 33px;
    border: 1px solid #DDD;
    background: #f5f5f5;
    padding-top: 0;
    padding-left: 0;

}
.group-box-1 .title .title-font{
    display: inline-block;
    font-size: 14px;
    font-family: ‘Microsoft Yahei‘,‘SimHei‘;
    font-weight: bold;
    color: #333;
    padding-left: 10px;
}
.group-box-1 .body {
    border: 1px solid #e4e4e4;
    border-top: none;
}

.tab-menu-box1 {
    border: 1px solid #ddd;
    margin-bottom: 20px;
}

.tab-menu-box1 .menu {
    line-height: 33px;
    height: 33px;
    background-color: #f5f5f5;
}

.tab-menu-box1 .content {
    min-height: 100px;
    border-top: 1px solid #ddd;
    background-color: white;
}

.tab-menu-box1 .menu ul {
    padding: 0;
    margin: 0;
    list-style: none;
    /*position: absolute;*/
}

.tab-menu-box1 .menu ul li {
    position: relative;
    float: left;
    font-size: 14px;
    font-family: ‘Microsoft Yahei‘,‘SimHei‘;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    border-right: 1px solid #ddd;
    padding: 0 18px;
    cursor: pointer;
}

.tab-menu-box1 .menu ul li:hover {
    color: #c9033b;
}

.tab-menu-box1 .menu .more {
    float: right;
    font-size: 12px;
    padding-right: 10px;
    font-family: "宋体";
    color: #666;
    text-decoration: none;
}

.tab-menu-box1 .menu a:hover {
    color: #f60 !important;
    text-decoration: underline;
}

.tab-menu-box1 .menu .current {
    margin-top: -1px;
    color: #c9033b;
    background: #fff;
    height: 33px;
    border-top: 2px solid #c9033b;
    z-index: 10;
}

.tab-menu-box-2 .float-title {
    display: none;
    top: 0px;
    position: fixed;
    z-index: 50;
}

.tab-menu-box-2 .title {
    width: 890px;
    border-bottom: 2px solid #b20101;
    border-left: 1px solid #e1e1e1;
    clear: both;
    height: 32px;
}

.tab-menu-box-2 .title a {
    float: left;
    width: 107px;
    height: 31px;
    line-height: 31px;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    border-top: 1px solid #e1e1e1;
    border-right: 1px solid #e1e1e1;
    background: url(/Content/images/bg4.png?3) 0 -308px repeat-x;
    text-decoration: none;
    color: #333;
    cursor: pointer;
}

.tab-menu-box-2 .title a:hover {
    background-position: -26px -271px;
    text-decoration: none;
    color: #fff;
}

.tab-menu-box-2 .content {
    min-height: 100px;
    background-color: white;
}

.tab-menu-box3 {
    border: 1px solid #ddd;
}

.tab-menu-box3 .menu {
    line-height: 33px;
    height: 33px;
    background-color: #f5f5f5;
}

.tab-menu-box3 .content {
    height: 214px;
    border-top: 1px solid #ddd;
    background-color: white;
}

.tab-menu-box3 .menu ul {
    padding: 0;
    margin: 0;
    list-style: none;
    /*position: absolute;*/
}

.tab-menu-box3 .menu ul li {
    position: relative;
    float: left;
    font-size: 14px;
    font-family: ‘Microsoft Yahei‘,‘SimHei‘;
    text-align: center;
    font-size: 14px;
    width:50%;
    cursor: pointer;
}

.tab-menu-box3 .menu ul li:hover {
    color: #c9033b;
}

.tab-menu-box3 .menu .more {
    float: right;
    font-size: 12px;
    padding-right: 10px;
    font-family: "宋体";
    color: #666;
    text-decoration: none;
}

.tab-menu-box3 .menu a:hover {
    color: #f60 !important;
    text-decoration: underline;
    font-weight: bold;
}

.tab-menu-box3 .menu .current {

    margin-top: -1px;
    color: #c9033b;
    background: #fff;
    height: 33px;
    border-top: 2px solid #c9033b;
    z-index: 10;
    font-weight: bold;

}

/*公共结束*/

实例:Tab菜单-css

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-1.12.4.js"></script>
</head>
<body>
    <div>
        <input class="selA" type="button" value="全选"/>
        <input class="selB" type="button" value="取消"/>
        <input class="selC" type="button" value="反选"/>
    </div>
    <table>
        <thead>
            <th>序号</th>
            <th> 姓名</th>
            <th> 年龄</th>
        </thead>
        <tbody>
            <tr>
                <td><input type="checkbox"/></td>
                <td>a</td>
                <td>18</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>b</td>
                <td>19</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>c</td>
                <td>20</td>
            </tr><tr>
                <td><input type="checkbox"/></td>
                <td>d</td>
                <td>21</td>

            </tr>

        </tbody>
        <script>
        $(".selA").click(function () {

            $(":input").prop("checked",true);
        })
        $(".selB").click(function () {
            $(":input").prop("checked",false);
        })
        $(".selC").click(function () {
            $("table :input").each(function () {
                if ($(this).prop("checked")){
                    $(this).prop("checked",false);
                }else{
                     $(this).prop("checked",true);
                }
            })
        })

        </script>
    </table>
</body>
</html>

实例:多选、反选和取消

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="jquery-1.12.4.js"></script>
    <style>
        body,img,ul {
            margin: 0;
            padding:0;
            list-style: none;
            border: 0;
        }
        .pg-header {
            background-color: #35536D;
        }
        .warp {
            width: 980px;
            margin: 0 auto;
        }
        .clearfix:after {
            content: ".";
            display: block;
            clear: both;
            height: 0 ;
            visibility: hidden;
        }
        .pg-header .logo   {
            float: left;
            padding: 5px 10px 5px 0px;
        }
        .pg-header .logo img {
            width: 110px;
            height: 40px;
        }
        .pg-header .nav ul li {
            float: left;

        }
        .pg-header .nav ul li a {
            display: block;
            text-decoration: none;
            color: #ccc;
            font-size: 16px;
            line-height: 50px ;
            font-family: "微软雅黑";
            padding: 0 20px ;
        }
        .pg-header .nav ul li a:hover{
            color: #fff;
            background-color: #1864aa;
        }
        .pg-body .catalog {
            position: absolute;
            top: 60px;
            width: 200px;
            background-color: #fafafa;
            border: 0px;
        }
        .pg-body .catalog.fixed{
            position: fixed;
            top:10px;
        }
        .pg-body .catalog .catalog-item{
            background-color: #fafafa;
        }
        .pg-body .content {
            position: absolute;
            top: 60px;
            width:700px;
            margin-left: 210px;
            background-color: #fafafa;
            overflow: auto;
        }
        .pg-body .content .section{
            height: 500px;
        }
    </style>
<html>
<body>
    <div class="pg-header">
        <div class="warp clearfix">
            <div class="logo">
                <a href="javascript:void (0)"><img src="3.png"/></a>
            </div>
            <div class="nav">
                <ul>
                    <li><a href="javascript:void(0)">首页</a></li>
                    <li><a href="javascript:void(0)">菜单一</a></li>
                    <li><a href="javascript:void(0)">菜单二</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="pg-body">
        <div class="warp">
            <div class="catalog">
                <div class="catalog-item"auto-to="function1"><a>第一页</a></div>
                <div class="catalog-item"auto-to="function2"><a>第二页</a></div>
                <div class="catalog-item"auto-to="function3"><a>第三页</a></div>
            </div>
            <div class="content">
                <div menu="function1"class="section"><h1>第一章</h1></div>
                <div menu="function2"class="section"><h1>第二章</h1></div>
                <div menu="function3"class="section"><h1>第三章</h1></div>
            </div>
        </div>
    </div>
    <script>
        window.onscroll=function () {
            var ws = $(window).scrollTop();
            if (ws >60){
                $(".catalog").addClass("fixed");
            }else{
                $(".catalog").removeClass("fixed");
            }
            if ($(document).height()==$(window).height()+ws){
                $(".catalog").children(":last").css("fontSize","40px").siblings().css("fontSize","16px");
                return;
            }
            $(".content").children().each(function () {
                var offset=$(this).offset().top;
                var total = $(this).height()+ offset;
                if (ws >offset && ws < total){
                    var index=$(this).attr("menu");
                    var new_inde="[auto-to="+index+"]";
                    $(new_inde).css("fontSize","40px").siblings().css("fontSize","15px");
                }
            })

        }
    </script>
</body>
</html>

实例:滚动菜单

3、文档处理

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div style="border: 1px solid #ddd;width: 600px;position: absolute;">
        <div id="title" style="background-color: black;height: 40px;"></div>
        <div style="height: 300px;"></div>
    </div>
<script type="text/javascript" src="jquery-1.12.4.js"></script>
<script>
    $(function(){
        $(‘#title‘).mouseover(function(){
            $(this).css(‘cursor‘,‘move‘);
        }).mousedown(function(e){
            //console.log($(this).offset());
            var _event = e || window.event;
            var ord_x = _event.clientX;
            var ord_y = _event.clientY;

            var parent_left = $(this).parent().offset().left;
            var parent_top = $(this).parent().offset().top;

            $(this).bind(‘mousemove‘, function(e){
                var _new_event = e || window.event;
                var new_x = _new_event.clientX;
                var new_y = _new_event.clientY;

                var x = parent_left + (new_x - ord_x);
                var y = parent_top + (new_y - ord_y);

                $(this).parent().css(‘left‘,x+‘px‘);
                $(this).parent().css(‘top‘,y+‘px‘);

            })
        }).mouseup(function(){
            $(this).unbind(‘mousemove‘);
        });
    })
</script>
</body>
</html>

实例:移动面板

时间: 2024-08-07 04:30:50

Web前端之jQuery的相关文章

【Web前端】jQuery界面优化

随着互联网的发展,网站的前端界面会越来越重要,它关注的是用户的直接体验.市场上同类型的网站越来越多,一个比其他同类网站更流畅.优雅的界面能让用户摈弃你的竞争对手.所以,让自己的网站前端运行的更快.界面更优美成为了一个重要的话题.从而,前端界面优化技术也成为了优秀前端开发人员必备的技能,这是核心竞争力. 今天介绍的是jQuery这个流行的前端javascript开发框架里的一些优化技术,这些优化技术需要我们深入理解JavaScript以及Web浏览器中DOM与JavaScript引擎关系. 减少D

10个极客Web前端开发jquery资源大荟萃

1.基于TweenMax.js的网页幻灯片 今天给大家带来一款基于TweenMax.js的网页幻灯片.这款幻灯片以不规则的碎片百叶窗的形式切换.切换效果非常漂亮. 在线演示 源码下载 2.pagePiling.js - 创建漂亮的全屏滚动效果 全屏滚动效果是最近非常流行的网页设计形式,带给用户良好的视觉和交互体验.pagePiling.js 这款 jQuery 插件可以帮助前端开发人员轻松实现这种效果. 在线演示 源码下载 3.使用 CSS3 伪元素实现立体的照片堆叠效 CSS3 里引入的伪元素

10款web前端基于jquery超实用jQuery插件大合集

1.纯CSS3实现多种箭头绘制及动画 今天要介绍的这款CSS3应用也非常实用,利用它可以用纯CSS3实现各种箭头的绘制,包括左右箭头.上下箭头以及各个方向的转弯箭头,另外还有一款更酷的CSS3箭头动画特效,可以用来做Loading加载动画.这么多箭头,你可以任选一个应用到项目中去. 在线演示 源码下载 2.基于jquery的手风琴显示详情 今天要各网友分享一款基于jquery的手风琴显示详情实例.当单击顶部箭头的时候,该项以手风琴的形式展示显示详情. 在线演示 源码下载 3.纯CSS3实现眨眼动

10款web前端超实用jQuery插件大合集

1.HTML5截图功能 可拖拽图片 截图在我们平常电脑应用中非常的广泛,包括开发者和一般的使用用户.今天介绍的这款HTML5截图应用可以帮助你在上传头像前截取自己的头像,你只需要拖拽移动图片即可选中要截取的部分,HTML5会自动将选取的图片自动生成一张新的图片来保存,从而完成截图的功能.另外,该HTML5截图应用还支持按住shift键实现图片同比例缩放. 在线演示 源码下载 2.纯CSS3动画按钮效果 5种漂亮样式 这次我们要来分享一款很不错的CSS3按钮动画,这款CSS3按钮一共有5种动画方式

超炫酷web前端的jQuery/HTML5应用搜罗

作为前端开发者,我们肯定都使用过非常多的jQuery插件,毋庸置疑,jQuery非常流行,尤其是结合HTML5和CSS3以后,让这些jQuery插件有了更多地动画效果,更为绚丽多彩. 1.HTML5/CSS3一组可爱的3D按钮 这是一款利用HTML5和CSS3制作而成的按钮组合,这款CSS按钮非常具有个性化.该CSS3按钮不仅具有3D的外观,点击按钮也具有非常立体的效果,更具有特点的是这款CSS3按钮的形状是不规则的,而且按钮中都有一个可爱的小图标. 在线演示 源码下载 2.jQuery Doc

10个web前端基于jQuery动画插件及源码

1.超赞的页面加载进度自动指示和 Ajax 导航效果 在页面中引入 Pace.js 和您所选择主题的 CSS 文件,就可以让你的页面拥有漂亮的加载进度和 Ajax 导航效果.不需要挂接到任何代码,自动检测进展.您可以选择颜色和多种效果,有简约,闪光灯,MAC OSX,左侧填充,顶部填充,计数器和弹跳等等. 在线演示 源码下载 2.ProgressBar.js – 漂亮的响应式 SVG 进度条 ProgressBar.js 是一个借助动态 SVG 路径的漂亮的,响应式的进度条效果.使用 Progr

10个web前端基于jQuery和css3动画插件及源码

1.jQuery横向手风琴图片展示插件 今天我们要来介绍一款非常酷的jQuery插件,它是一款横向的手风琴图片展示切换插件,每一张图片初始都是水平层叠在一起,点击图片后即可切换至下一张,并且在图片切换时出现水平移动的动画特效.另外你可以定义任意数量的图片应用在这个手风琴图片插件中. 在线演示 源码下载 2.纯css3实现的鼠标经过按钮特效 今天再给大家带来一款纯css3实现的鼠标经过按钮特效.这款按钮非常简单,但效果很好,非常漂亮. 在线演示 源码下载 3.FreeIconMaker - 在线创

Web前端基础——jQuery(一)

前几天回老家呆了几天,几乎没有怎么学习新的知识,这期间一直有断断续续的看<Java编程思想>,还刷了一些前沿消息,也算没闲着.今天开始学习jQuery啦,继续前进. 在网上查了,买了这本书.现在是一边搜视频,一边看这本书. 认识jQuery,我将从以下几方面进行讲解. 一.JavaScript和JavaScript库 随着Web 2.0的兴起,JavaScript受重视的程度提高,带动JavaScript程序库也蓬勃发展起来. 过程:Prototype->Dojo->jQuery-

10款web前端基于Jquery的动画源码

1.使用 CSS3 动感的图片标题动画效果 在网站中,有很多地方会需要在图片上显示图片标题.使用 CSS3 过渡和变换可以实现动感的鼠标悬停显示效果.没有使用 JavaScript,所以只能在支持 CSS3 动画的现代浏览器中才能正常工作.您可以查看网页的源代码,了解动画是如何工作的. 在线演示 源码下载 2.简单的轻量级的 jQuery 仪表板插件 sDashboard 是一个轻量的仪表板 jQuery 插件,转换一个对象数组到仪表板.数组中的每个对象将被呈现为一个仪表板组件,可以通过左右拖

10款web前端基于jquery的页面代码

1.基于jquery实现的带按钮的图片左右滚动切换 jquery带按钮的图片滚动切换代码是一款jquery制作带按钮的图片左右滚动切换特效代码 在线演示 源码下载 2.基于jQuery的图片上下左右无缝连续循环滚动 imgscroll插件是一款支持图片焦点滚动(支持渐变和滚动),图片连续无缝循环滚动的js库,依赖于jQuery图片无缝连续循环滚动 支持上下左右的滚动. 在线演示 源码下载 3.jquery实现的fixed固定层时间轴动态效果 jquery实现的fixed固定层时间轴动态效果源码,