jquery swiper自定义pagination的方法

jquery swiper自定义pagination的方法

<script>
var swiper = new Swiper('.swiper-container', {
  pagination: '.swiper-pagination',
  paginationClickable: true,
  paginationBulletRender: function (swiper, index, className) {
      return '<span class="' + className + '">' + (index + 1) + '</span>';
  }
});  
</script>

具体详情http://www.swiper.com.cn/api/pagination/2014/1217/70.html

ps:自定义classname方法

   bulletClass: 'chanpin-bullet',
        bulletActiveClass: 'chanpin-bullet-active',

jquery鼠标经过弹出层写法

jquery鼠标经过弹出层写法

<div class="navitem"><a href="/index.php?c=news&amp;a=index&amp;id=52">新闻中心</a>
<div class="navitemlist" style="display: none;">
<a href="/index.php?c=news&amp;a=index&amp;id=52">公司新闻</a>
<a href="/index.php?c=news&amp;a=index&amp;id=53">媒体报道</a>
</div>
</div>
    $(".navitem").hover(function(){
        $(this).children('a').next('.navitemlist').fadeIn();
    },function(){
        $(this).children('a').next('.navitemlist').css('display','none');
    });
.header .navitem {
    height: 100%;
    padding-left: 20px;
    padding-right: 20px;
    display: block;
    line-height: 102px;
    font-size: 16px;
    color: #242169;
    border-bottom: 1px #FFF solid;
    text-decoration: none;
    float: left;
    position: relative;
}
.navitemlist {
    height: auto;
    overflow: hidden;
    position: absolute;
    left: 0px;
    top: 75px;
    background: #FFF;
    z-index: 9999;
    text-align: left;
    display: none;
}

jquery向上滚动页面的写法

jquery向上滚动页面的写法

  $('.arrow_top').on('click',function () {
        $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
        $body.animate({scrollTop: 0}, 1000);

    })
    $(window).scroll(function() {
        if(parseInt($(document).scrollTop())>=300){
            $('.arrow_top').fadeIn();
        }else{
            $('.arrow_top').fadeOut();
        }
    });

jquery json对象转换

jquery json对象转换

parse用于从一个字符串中解析出json对象,如

var str = '{"name":"huangxiaojian","age":"23"}'

结果:

JSON.parse(str)



Object

age: "23"
name: "huangxiaojian"
__proto__: Object



注意:单引号写在{}外,每个属性名都必须用双引号,否则会抛出异常。



stringify()用于从一个对象解析出字符串,如


var
 a = {a:1,b:2}

结果:

JSON.stringify(a)


"{"a":1,"b":2}"










其他key value写法
     var param = [];
        param.push({"timu":1,"sel":2});
        param.push({"timu":2,"sel":3});
       var json = JSON.stringify(param);
       console.log(json);







jquery实现tab菜单点击换菜单图片方法

jquery实现tab菜单点击换菜单图片方法 代码如下

<div class="menulist">
<p class="active" cur="p1">
    <img class="img1" src="{$yuming}/images/menu/jituanjianjie.jpg" alt="">
    <img class="img2" src="{$yuming}/images/menu/jituanjianjie_h.jpg" alt="">
</p>
<p cur="p2">
    <img class="img1"   src="{$yuming}/images/menu/jituanrongyu.jpg" alt="">
    <img class="img2"  src="{$yuming}/images/menu/jituanrongyu_h.jpg" alt="">
</p>
<p cur="p3">
    <img class="img1"  src="{$yuming}/images/menu/dashiji.jpg" alt="">
    <img class="img2"  src="{$yuming}/images/menu/dashiji_h.jpg" alt="">
</p>
<p  cur="p4">
    <img class="img1"  src="{$yuming}/images/menu/kongjian.jpg" alt="">
    <img class="img2" src="{$yuming}/images/menu/kongjian_h.jpg" alt="">
</p>
</div>
.menulist{
    width:100%;
    height:auto;
    overflow: hidden;
    background: #b49b87;
}
.menulist p{
    width: 23.2%;
    text-align: center;
    display: block;
    float: left;
    padding: 0px;
    margin: 0px;
    margin-left: 0.2rem;
    margin-top: 0.4rem;
    float: left;
    position: relative;
}
.menulist p img{
    width:100%;
}
.img1{
    width:100%;
    position: absolute;
    left:0px;
    top:0px;
    z-index: 2;
}
.active .img1{
    display: none;
}
    $('.menulist p').on('click', function () {
        $(this).addClass('active');
        $(this).siblings('p').removeClass("active");
 
    })

ps 原理就是 点击控制class

jquery实现比较靠谱的手风琴代码

比较靠谱的手风琴代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>自制手风琴</title>
    <script type="text/javascript" src="/index/js/jquery.min.js"></script>
    <style type="text/css">


        .menulist li {
            display: none;
        }


    </style>
</head>
<body>
<div class="menulist">
    <ul>
        <span>AAAAA<b>+</b></span>
        <li>11111</li>
        <li>11111</li>
        <li>11111</li>
        <li>11111</li>
    </ul>
    <ul>
        <span>BBBBB<b>+</b></span>
        <li>22222</li>
        <li>22222</li>
        <li>22222</li>
    </ul>
    <ul>
        <span>CCCCC<b>+</b></span>
        <li>33333</li>
        <li>33333</li>
        <li>33333</li>
        <li>33333</li>
        <li>33333</li>
    </ul>
    <ul>
        <span>DDDDD<b>+</b></span>
        <li>44444</li>
        <li>44444</li>
    </ul>
    <ul>
        <span>EEEEE<b>+</b></span>
        <li>55555</li>
        <li>55555</li>
        <li>55555</li>
    </ul>
</div>
<script type="text/javascript">
    $(function () {
        $('span').click(function () {
            if ($(this).siblings('li').hasClass('on')) {
                $(this).siblings('li').slideUp(500).removeClass('on');
                $(this).children('b').text('+');
            } else {
                $(this).siblings('li').slideDown(500).addClass('on');
                $(this).children('b').text('-');
            }
        });
    });
</script>
</body>
</html>

jquery预加载显示百分比

jquery预加载显示百分比

  <img class="bj loadimg" loadimg="/weiqingshu/images/1/bj.jpg"/>

  imgNum=0;
    var load_img = [];
  /*$('.loadimg').each(function () {
        var loadimg=$(this).attr('loadimg');
        load_img.push(loadimg);
    })*/
    load_img.push( '/caigeci/images/answer0.jpg' );
    load_img.push( '/caigeci/images/answer1.jpg' );
    /*ss*/
    jQuery.imgpreload(load_img, {
        each: function () {
            /*this will be called after each image loaded*/
            var status = $(this).data('loaded') ? 'success' : 'error';
            if (status == "success") {
                var v = (parseFloat(++imgNum) / load_img.length).toFixed(2);
                console.log(Math.round(v * 100) + "<sup>%</sup>");
            }
        },
        all: function() {
            console.log('全部加载完成');
   /*$('.loadimg').each(function () {
                var loadimg=$(this).attr('loadimg');
                $(this).attr('src',loadimg);
            })*/
        }
    });

ps:加载的文件个数 /全部文件个数 的百分比就是进度