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实现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:加载的文件个数 /全部文件个数 的百分比就是进度

jquery ajax分页写法

jquery ajax分页写法
我用的是laypage插件

前端代码

        function demo(curr) {
            $.getJSON('/home/index/getinfo', {
                page: curr || 1 //向服务端传的参数,此处只是演示
            }, function (res) {
                var html = '';
                var list = res.data.list;
                $.each(list, function (k, v) {
                    html += '<div';
                    if(k%2==0){
                        html += ' style="margin-left:0px;"';
                    }
                    html += ' class="perinfocontent" onclick="window.location.href=\'content.html?id='+v['id']+'\'">';
                    html += '<img src="'+v['fengmiantu']+'" alt="" class="pic">';
                    html += '<div class="infos">';
                    html += '<div class="title">'+v['title']+'</div>';
                    html += '<div class="tiyao">'+v['content']+'</div>';
                    html += '<div class="publishtime">2017 / 1 / 23</div>';
                    html += '</div>';
                    html += '</div>';
                });

                $('.infocontent').html(html);

                //显示分页
                laypage({
                    cont: $('#page3'), //容器。值支持id名、原生dom对象,jquery对象,
                    pages: res.data.pagecount, //总页数
                    skip: true, //是否开启跳页
                    skin: 'molv',
                    curr: curr || 1, //当前页
                    jump: function (obj, first) { //触发分页后的回调
                        if (!first) { //点击跳页触发函数自身,并传递当前页:obj.curr

                        demo(obj.curr);
                        }
                    }
                });

            });
        };
//运行
        demo();

PHP代码

    public function getinfo(){
        $page = intval($_GET['page']);
     
        if(empty($page)){
            $page=1;
        }
        $startpos=$page-1;
        //返回每页的数据
        $percount = 8;
        $VModel = new HuanShanVoteModel();
        $sql = 'select * from wz_content order by id desc limit '.$startpos*$percount.',' . $percount;

        $result = $VModel->query($sql);
        foreach ($result as $k => $v) {
            $result[$k]['content'] = substr(stripHTML(htmlspecialchars_decode($v['content'])), 0, 30) . '......';
            $result[$k]['time'] = date('Y / M / D', $v['time']);
        }

        //返回总页码数
        $VModel = new HuanShanVoteModel();
        $sql = 'select title,content from wz_content';
        $alllist = $VModel->query($sql);
        $count = count($alllist);
        $pagecount = ceil($count / $percount);

        echo json_encode(array('success'=>1,'msg'=>'查询成功','data' => array('pagecount' => $pagecount, 'list' => $result)));
        exit();
    }