Jquery代码总结

1.轮播图:

<script src="jquery-1.8.3.min.js"></script>
<script>
    var index=0;
    var len=$(".banner .lt .top .left ul li").length;
    $(".banner .lt .top .left .click .prev").click(function(){
        index--;
        if(index<0){
            index=len-1;
        }
        $(".banner .lt .top .left ul li").hide().eq(index).show();
        $(".banner .lt .top .left ol li ").removeClass("cot").eq(index).addClass("cot")
    });
    var dt=function(){            /*function dt()声明式  实际开发中常用  前后都能调用*/
        /* 表达式 只能后面调用*/
        index++;
        if(index>len-1){
            index=0;
        }
        $(".banner .lt .top .left ul li").hide().eq(index).show();
        $(".banner .lt .top .left ol li ").removeClass("cot").eq(index).addClass("cot")
    };
    $(".banner .lt .top .left .click .next").click(function(){
        dt();
    });
    var timer=setInterval(dt,1000);
    $(".banner .lt .top .left").mouseover(function(){
        clearInterval(timer);
    });
    $(".banner .lt .top .left").mouseout(function(){
        timer=setInterval(dt,1000);
    });
    var timer1=null;
    $(".banner .lt .top .left ol li").mouseover(function(){
        clearTimeout(timer1);
        var that=$(this);
        timer1=setTimeout(function(){
            index=that.index();
            that.addClass("cot").siblings().removeClass("cot");
            $(".banner .lt .top .left ul li").hide().eq(index).show();
        },200)
    });

2.红白耳机切换:

Html :<td class="tu4">
    <i></i>
    <!--<img src="data:images/33333333_03.png" alt="">-->
    <!--<img class="hong" src="data:images/enhe.png" alt="">-->
</td>

Css部分:.main .lt .biao .bto table tr .tu4 i{
    display: block;
    background: url("../images/icons-01.gif")no-repeat  -9px -79px;
    width: 21px;
    height: 21px;
    margin: auto;
}

.main .lt .biao .bto table tr .tu4 .hong{
    display: block;
    background: url("../images/icons-01.gif")no-repeat -10px -184px;
    width: 21px;
    height: 21px;

}

Jq部分:$("table .tu4").click(function() {
    $("table .tu4 i").removeClass("hong");
    $(this).find("i").addClass("hong");
})

3.下拉菜单:

$(".header ol li").hover(function(){
    $(this).find("ul li").stop().slideDown();
},(function(){

$(this).find("ul li").stop().slideUp();
})
)

4.一些特有属性:

<script>
    $("input").click(function(){
        $(".box").delay(1000).animate({width:600, height:600},1000,
        function(){
            alert("鼓掌")
        })
    })//animate属性的应用
    var i=0;
    $(".box").mousedown(function(){
        i="按下"
        console.log(i);
    })

    $(".box").mouseup(function(){
        i="抬起"
        console.log(i);
    })//mousedown和mouseup属性的应用
    $("input").keydown(function(e){
        console.log(e.key);
        if(e.key=="Enter"){
            console.log("恭喜你");}
        else{
            console.log("chuqu");
        }
    });//keydown属性的应用
    $(".box").mousemove(function(e){
        $(".box1").css({left:5+e.pageX,top:10+e.pageY});
    }).hover(function(){
        $(".box1").show()
    },function(){
        $(".box1").hide()
    }
    )//mousemove属性的应用
</script>

5.图片放大特效:

<body>
<div class="dbox">
    <div class="box">
        <img src="imge/1.jpg" alt="">
    </div>
    <div class="box">
        <img src="imge/2.jpg" alt="">
    </div>
    <div class="box">
        <img src="imge/3.jpg" alt="">
    </div>
    <div class="box">
        <img src="imge/4.jpg" alt="">
    </div>
</div>
<div class="box1"></div>

</body>
<script src="jquery-1.8.3.min.js"></script>
<script>

    $(".box").mousemove(function(e){

        $(".box1").css({left:5+e.pageX,top:10+e.pageY});
    }).hover(function(){
               var src=$(this).find("img").attr("src");
                $(".box1").show().css({backgroundImage:"url("+src+")"})
            },function(){
                $(".box1").hide();
            )

</script>

6.图片特效:

<div class="box">
    <ul>
        <li><img src="imge/xiao1.jpg" alt=""></li>
        <li><img src="imge/xiao2.jpg" alt=""></li>
        <li><img src="imge/xiao3.jpg" alt=""></li>
        <li><img src="imge/xiao4.jpg" alt=""></li>
    </ul>
</div>
<div class="box1"></div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
    $(".box ul li").click(function(){
    }).hover(function(){
        index=$(this).index();
                $(".box1").show().css({backgroundImage:"url(imge/da"+(index+1)+".jpg)"})
            }
    ).hover(function(){
        $(this).find("img").css({zIndex:999}).stop().animate({
            width:200,height:200,top:-50,left:-50
        },400);
    },function(){
        $(this).find("img").css({zIndex:1}).stop().animate({
            width:100,height:100,top:0,left:0
        });
    })
</script>

6.图片的动态效果:

<style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 640px;
            height: 320px;
            
            margin: 50px auto;
            border: 3px solid pink;
            overflow: hidden;
        }
        .box ul{
            width: 1000px;
            background-color: #00030C;
        }

        .box ul li{
            width: 80px;
            height: 320px;
            background-color:white;
            float: left;
            list-style: none;
            background-size: 480px 320px;
            /*background-size:100%;*/
            cursor: pointer;
            /*background-repeat: no-repeat;
            background-position: center;*/
        }

    </style>
</head>
<body>
<div class="box">
    <ul>
        <li style="background-image: url(imge/pic1.jpg)"></li>
        <li style="background-image: url(imge/pic2.jpg)"></li>
        <li style="background-image: url(imge/pic3.jpg)"></li>
        <li style="background-image: url(imge/pic4.jpg)"></li>
        <li style="background-image: url(imge/pic5.jpg)"></li>
        <li style="background-image: url(imge/pic6.jpg)"></li>
        <li style="background-image: url(imge/pic7.jpg)"></li>
        <li style="background-image: url(imge/pic8.jpg)"></li>
    </ul>
</div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
    $(".box ul li").hover(function(){
        $(this).stop().animate({width:430},200).siblings().
                stop().animate({width:30},200)
    },function(){
        $(".box ul li").stop().animate({width:80},200)
    })
</script>

没有注释部分:

加上注释部分:

7.上下拉菜单:

<style>
        .box-wrap{
            width: 300px;
        }
    </style>
</head>
<body>
<div class="box-wrap">
    <div class="box">
        <div class="box-top">
            <h1>我是一级菜单</h1>
        </div>
        <div class="box-bottom">
            <p>我是二级菜单</p>
            <p>我是二级菜单</p>
            <p>我是二级菜单</p>
            <p>我是二级菜单</p>
        </div>
    </div>
    <div class="box">
            <div class="box-top">
                <h1>我是一级菜单</h1>
            </div>
            <div class="box-bottom">
                <p>我是二级菜单</p>
                <p>我是二级菜单</p>
                <p>我是二级菜单</p>
                <p>我是二级菜单</p>
            </div>
    </div>
    <div class="box">
                <div class="box-top">
                    <h1>我是一级菜单</h1>
                </div>
                <div class="box-bottom">
                    <p>我是二级菜单</p>
                    <p>我是二级菜单</p>
                    <p>我是二级菜单</p>
                    <p>我是二级菜单</p>
                </div>
    </div>
</div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
    $(".box").click(function(){
        $(this).find(".box-bottom").slideToggle();
        $(this).siblings().find(".box-bottom").slideUp();
    })
</script>

效果图:

8.轮播图的第二方式:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
      margin: 0;
            padding: 0;
        }
        .box{
            width: 600px;
            height: 300px;
            position: relative;
            border: 2px solid black;
            overflow: hidden;
            margin: 100px auto;
        }
        li{
            list-style: none;
        }
        .box ul{
            width: 4000px;
            position: absolute;
            left: 0;
            top: 0;
        }
        .box ul li{
            width: 600px;
            height: 300px;
            font: 900 68px/300px "simsun";
            text-align: center;
            
            float: left;
        }
        .box ol{
            position: absolute;
            width: 140px;
            height: 20px;
            background-color: #00c6ff;
            left: 50%;
            margin-left: -70px;
            bottom: 10px;
            border-radius: 10px;
        }
        .box ol li{
            width: 20px;
            height: 20px;
            background-color: yellow;
            float: left;
            border-radius: 100%;
            cursor: pointer;
        }
        .box ol li+li{
            margin-left: 10px;
        }
        .box ol li.col{
            background-color: black;
        }
        .box .click div{
            width: 30px;
            height: 40px;
            font:900 20px/40px "simsun";
            position: absolute;
            background-color: rgba(0,0,0,.5);
            top:50%;
            margin-top: -20px;
            color: white;
            text-align: center;
            cursor: pointer;
        }
         .click .next{
            right: 0;
        }
    </style>
</head>
<body onselectstart="return false">
<div class="box">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>1</li>
    </ul>
    <ol>
        <li class="col"></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ol>
    <div class="click">
        <div class="prev">
            <
        </div>
        <div class="next">
            >
        </div>
    </div>

</div>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script>
    var index=0;        /* ul li加索引*/
    var bb=0;           /*ol li 加索引*/
    var len=$(".box ul li").length;   /* ui li 声明总个数*/
    $(".box ol li").click(function(){  /*给小圆圈设置点击事件*/
        index=$(this).index();   /*调用这个索引值*/
       bb=$(this).index();
        $(".box ul").animate({left:-(index*600)},1000);   /*图片进行向左切换*/
        $(".box ol li").removeClass("col").eq(bb).addClass("col"); /*先让黑点全部覆盖,然后一个一个显示出来*/
    })
    var fa=true;          /*声明此过程是为了禁止刷流量*/
    $(".box .click .prev").click(function(){   /* 给左按键设置点击事件*/
        if(fa==true){
            fa=false;
            bb--;
            if (bb<0){
                bb=len-2;          /* 左点击时,给小圆点设置循环,让小圆点和图片同时进行*/
            }
            $(".box ol li").stop().removeClass("col").eq(bb).addClass("col");
            index--;
            if (index<0) {
                index = len-2;
                $(".box ul").css({left:-(len-1)*600});    /*让图片瞬间转到第五张图片*/
                /* $(".box ul").css({left:-((index+1)*600)});*/
            }
            $(".box ul ").stop().animate({left:-(index*600)},1000,  /*让图片进行左循环*/
                    function () {
                        fa = true;
                    })
        }
        })
    var fa=true;
    $(".box .click .next").click(function(){
        if(fa==true){
            fa=false;
            bb++;
            if(bb>len-2){
                bb=0             /*当右点击时,让小圆圈随着图片进行右循环*/
            }
            $(".box ol li").stop().removeClass("col").eq(bb).addClass("col");
            index++;
            if(index>len-1){
                index=1;
                $(".box ul").css({left:0});  /* 当图片循环到最右端时,让图片立即返回到第一张图片*/
            }
            $(".box ul ").stop().animate({left:-(index*600)},1000    /*让图片进行右循环*/
                    ,function(){
                        fa=true;
                    });
        }
    })
</script>

总结jq的一些特效的更多相关文章

  1. jq图片切换特效

    首先引入js,内容如下: (function($){$.fn.slides=function(option){option=$.extend({},$.fn.slides.option,option) ...

  2. 【h5+c3】web前端实战项目、快装webapp手机案例源码

    快装WebApp项目(Web移动端开发案例)webapp移动端项目源码.html5+css3实战案例分享.微信端H5实例开发 简介快装WebApp是一个面向移动端的快速装修app,此项目为手机端:使用 ...

  3. 动画特效的原生、jQ和CSS3方法

    最近一直在看运动的JS特效,主要看的是原生写法,太麻烦了,最终看到写了个运动的方法,后面可以直接引用,然后发现这个方法和jQ其实差不多了,代码分别如下: 基本的HMTL和CSS <!DOCTYP ...

  4. jQ小图标上下滑动特效

    嗯,又到了,夜静饥寒的时候,手指颤抖,回望去,屋内满是寂静,寥寥绰影,咳咳咳,想我程序员之路还没到终点...就...咳咳咳 好了日常神经结束,还要涂我的唇膏.还剩下,最后一章,js动画(四),明天放上 ...

  5. JQ滚动特效

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  6. 手风琴图片和钢琴导航栏JQ滑动特效

    手风琴JQ滑动特效 1.效果预览: 2.相关代码: <!DOCTYPE html> <html lang="en"> <head> <me ...

  7. 基于jQ+CSS3页面滚动内容元素动画特效

    今天给大家分享一款基于jQ+CSS3页面滚动内容元素动画特效.这是一款基于jQuery+CSS3实现的页面滚动代码.该实例适用于适用浏览器:360.FireFox.Chrome.Safari.Oper ...

  8. 上一个树形菜单的改进,增添了数据绑定功能而非仅仅的jq特效

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  9. 网页JQ基础之jq-隐藏以及显示特效

    简单的 隐藏以及显示的 JQ 的代码如下: <!DOCTYPE html> <html> <head> <script src="/jquery/j ...

随机推荐

  1. android studio创建一个最简单的跳转activity

    实现目的:由mainActivity跳转到otherActivity 1.写好两个layout文件,activity_main.xml和otherxml.xml activity_main.xml & ...

  2. tomcat7以上,ajax post参数后台获取不到的问题

    AJAX post传参后台获取不到查询参数. 网上找了各种方法,包括设置content-type,又是把json转成json格式字符串,问题依然存在,但是把post改成get又可以获取到,百思不得其解 ...

  3. hdu2410(水)

    题意 如果两个数字除了带问号的位以外都相同,我们称这两个数可以相互匹配 给你两个数,其中第一个数字里有一些问号,问有多少个大于第二个数的数字可以和第一个数字匹配 一开始懒得读题,到网上搜题意,结果居然 ...

  4. 请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)

    程序异常,错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (pro ...

  5. Java编程思想总结笔记The first chapter

    总觉得书中太啰嗦,看完总结后方便日后回忆,本想偷懒网上找别人的总结,无奈找不到好的,只好自食其力,尽量总结得最好. 第一章  对象导论 看到对象导论觉得这本书 目录: 1.1 抽象过程1.2 每个对象 ...

  6. jsp注册页面验证,easyui的jsp+js表单验证

    1.1下面的代码是写在Js里面的,就直接写进去不用什么其他东西,这样一个表单验证就好了(1.2图) $.extend($.fn.validatebox.defaults.rules, { phone: ...

  7. 深入浅析JavaScript中的constructor

    constructor 属性返回对创建此对象的数组函数的引用.本文给大家介绍JavaScript中的constructor ,需要的朋友参考下吧 定义和用法 constructor 属性返回对创建此对 ...

  8. java 关键字final

    一.最终的意思,可以修饰类,方法,变量.特点: A:它修饰的类,不能被继承. B:它修饰的方法,不能被重写. C:它修饰的变量,是一个常量.二.面试相关: 1.局部变量基本类型 值不能发生改变 例如: ...

  9. HTML中的行内元素和框元素详解

    定义 传统的块级元素定义中只是说明了在文档流中形成了一个块,在前后加换行,这里有些笼统. 其实框元素是指宏观上的框元素,它包括3种类型:1.本身就是块级元素 2.dispaly被设置为类block 3 ...

  10. (转)如何在maven的pom.xml中添加本地jar包

    1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将 ...