博客列表 >微博案例(时间:2019年 1月24日 18:03)

微博案例(时间:2019年 1月24日 18:03)

过儿的博客
过儿的博客原创
2019年01月24日 18:03:21627浏览

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>微博案例</title>
      <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
      <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div id="list">
        <div class="box clearfix">
    <!-- 删除说说按钮 close-->
            <a class="close" href="javascript:;">×</a>
            <img class="head" src="image/1.png" alt="">
            <div class="content">
                <div class="main">
                    <p class="txt">
                        <span class="user">西门大官人: </span>
                          ~ All the luck is for you. ~
                    </p>
                    <img class="pic" src="image/img1.jpg" alt="">
                </div>
                <div class="info clearfix">
                    <span class="time">02-14 23:01</span>
                    <a class="praise" href="javascript:;">赞</a><!-- 给说说点赞 praise -->
                </div>
                <div class="praises-total" total="4" style="display: block;">4个人觉得很赞</div>
                <div class="comment-list"><!--评论内容--> 
                    <div class="comment-box clearfix" user="self"><!--   每次评论要添加的内容跟标签   -->
                        <img class="myhead" src="image/4.jpg" alt="">
                        <div class="comment-content">
                            <p class="comment-text"><span class="user">我:</span>你说的都对……</p>
                            <p class="comment-time">
                                2019-01-19 14:36
                                <a href="javascript:;" class="comment-praise" total="1" my="0" style="display: inline-block">1赞</a>
                                <a href="javascript:;" class="comment-operate">删除</a>
                            </p>
                        </div>
                    </div>
                    <!--添加结束-->                                                           
                </div>
    <!--评论内容结束--> 
                <div class="text-box">
                        <textarea class="comment" placeholder="评论…"></textarea>
                        <button class="btn">回 复</button>
                        <span class="word"><span class="length">0</span>/140</span>
                </div>                
            </div>            
        </div> 
                       
        <div class="box clearfix">
            <a class="close" href="javascript:;">×</a>
            <img class="head" src="image/2.jpg" alt=""/>
            <div class="content">
                <div class="main">
                    <p class="txt">
                        <span class="user">欧阳克 : </span>三亚的海滩很漂亮。
                    </p>
                    <img class="pic" src="image/img5.jpg" alt=""/>
                </div>
                <div class="info clearfix">
                    <span class="time">02-14 23:01</span>
                    <a class="praise" href="javascript:;">赞</a>
                </div>
                <div class="praises-total" total="0" style="display: none;"></div>
                <div class="comment-list">
                    <div class="comment-box clearfix" user="other">
                        <img class="myhead" src="image/3.png" alt="">
                        <div class="comment-content">
                            <p class="comment-text"><span class="user">韦小宝:</span>我也想去三亚。</p>
                            <p class="comment-time">
                                2019-01-19 14:36
                                <a href="javascript:;" class="comment-praise" total="0" my="0">赞</a>
                                <a href="javascript:;" class="comment-operate">删除</a>
                            </p>
                        </div>
                    </div>
                </div>
                <div class="text-box">
                        <textarea class="comment" placeholder="评论…"></textarea>
                        <button class="btn">回 复</button>
                        <span class="word"><span class="length">0</span>/140</span>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript">
 $(function(){
     $('.comment').on('keyup',function(){
         var len=$(this).val().length  //获取文本框内容的字符长度
         $(this).parents('.text-box').find('.length').text(140-len);
     })
     $(document).on('click','.btn',function(){
         var val=$(this).prev().val()  //pre()获得元素紧邻前一个同胞元素
         if(val==''){
             alert('留言内容不能为空!')
         }else{
            var date=new Date()
            var yy=date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()
            var html=' <div class="comment-box clearfix" user="sele"><img class="myhead" src="image/4.jpg" alt=""><div class="comment-content"><p class="comment-text"><span class="user">我:</span>'+val+'</p><p class="comment-time">'+yy+'<a href="javascript:;" class="comment-praise" total="1" my="0" style="display:inline-block">1赞</a><a href="javascript:;" class="comment-operater">删除</a></p></div></div>'
            $(this).parents('.box').find('.comment-list').append(html)  //添加评论
            $(this).parents('.box').find('.comment').val('')  //清空输入框
            $(this).parents('.box').find('.length').text('0')
            $(this).prev().height(20)
         }
     })
     $('.comment').click(function(){
         $(this).height(80)
     })
       // 动态绑定主体点赞 只能赞一次
       $(document).on('click','.info>a',function(){
                if(! $(this).hasClass('praise_2')){
                    //不存在praise_2 说明还没有点赞 就添加上赞的样式,去掉原来的样式
                    $(this).addClass('praise_2').removeClass('praise');
                    //改变文字
                    $(this).html('已赞');
                    // 获取到赞的区块
                    let tot = $(this).parent().siblings('.praises-total');
                    // 赞的总人数+1 并显示
                    tot.attr('total',parseInt(tot.attr('total')) + 1);
                    tot.html(tot.attr('total') + '个人觉得很赞');
                    tot.show();
                }else{
                    //已赞提示
                    alert('你已经赞过了!');
                }
            })
      // 动态绑定评论点赞 可累加
      $(document).on('click','.comment-praise',function(){
                //自己 赞的+1
                $(this).attr('my',parseInt($(this).attr('my')) + 1)
                // 总数也加1  并改变赞的次数
                $(this).attr('total',parseInt($(this).attr('total')) + 1) ;
                $(this).html($(this).attr('total') + '赞');
            });

            //动态绑定评论删除点击事件 
            $(document).on('click','.comment-operate',function(){
                if(confirm('确认删除?')){
                    //确认删除评论区块
                    $(this).parents('.comment-box').remove();
                }
            });

            //动态绑定删除某个主体点击事件 
            $(document).on('click','.close',function(){
                if(confirm('确认删除?')){
                    //确认删除某个主体
                    $(this).parents('.box').remove();
                }
            });

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

运行实例 »

点击 "运行实例" 按钮查看在线实例

样式代码:

实例

body { font-size: 12px; line-height: 120%; text-align: center; color:#333; padding: 20px;}
a { color: #333; text-decoration: none;}
a:hover { text-decoration: underline;}
* { margin: 0; padding: 0; border: none;}
.clearfix:after { content:"."; display:block; height:0; clear:both; visibility:hidden}
.clearfix {height:1%;}
#list { margin: 0 auto; text-align: left; width: 540px;}
.box { border-top: 1px solid #eee; position: relative;  width: 540px; padding: 20px 0}
.box:hover .close { display: block;}
.close { display: none; top:0px; right: 0px; width: 28px; height: 28px; border: 1px solid #eee; position: absolute; background: #f2f4f7; line-height: 27px; text-align: center;}
.close:hover { background: #c8d2e2; text-decoration: none;}
.head { float: left; width: 50px; height:50px; margin-right: 10px;border-radius:25px;}
.content { float: left; width: 440px;}
.main { margin-bottom: 10px;}
.txt { margin-bottom: 10px;}
.user { color: #369; }
.pic { margin-right: 5px; width: 200px; border: 1px solid #eee;}
.info { height: 20px; line-height: 19px; font-size: 12px; margin: 0 0 10px 0;}
.info .time { color: #ccc; float: left; height: 20px; padding-left: 20px; background: url("./images/bg1.jpg") no-repeat left top;}
.info .praise { color: #369; float: right; height: 20px; padding-left: 18px; background: url("./images/bg2.jpg") no-repeat left top;}
.praise_2{background: url("./images/bg3.jpg") no-repeat left top;color: #369; float: right; height: 20px; padding-left: 18px;}
.praises-total { margin: 0 0 10px 0; height: 20px; background: url("./images/praise.png") no-repeat 5px 5px rgb(247, 247, 247); padding: 5px 0 5px 25px; line-height: 19px;}
.comment-box { padding: 10px 0; border-top: 1px solid #eee;}
.comment-box:hover { background: rgb(247, 247, 247);}
.comment-box .myhead { float: left; width: 30px; height: 30px; margin-right: 10px;border-radius:15px; }
.comment-box .comment-content { float: left; width: 400px; }
.comment-box .comment-content .comment-time { color: #ccc; margin-top: 3px; line-height: 16px; position: relative;}
.comment-box .comment-content .comment-praise { display: none; color: #369; padding-left: 17px; height: 20px; background: url("./images/praise.png") no-repeat;  position: absolute; bottom: 0px; right: 44px;}
.comment-box .comment-content .comment-operate { display: none; color: #369; height: 20px;  position: absolute; bottom: 0px; right: 10px;}
.comment-box .comment-content:hover .comment-praise { display: inline-block;}
.comment-box .comment-content:hover .comment-operate { display: inline-block;}
.text-box .comment { border: 1px solid #eee; display: block; height: 15px; width: 428px; padding: 5px; resize: none; color: #ccc}
.text-box .btn { font-size: 12px; font-weight: bold;float: right; width: 65px; height: 25px; border: 1px solid #0C528D; color: #fff; background: #4679AC;}
.text-box .btn-off { border: 1px solid #ccc; color: #ccc; background: #F7F7F7;}
.text-box .word{  float: right; margin: 7px 10px 0 0; color: #666;}
.text-box-on .comment{ height: 50px; color: #333;}
.text-box-on .btn{ display: inline;}
.text-box-on .word{ display: inline;}

运行实例 »

点击 "运行实例" 按钮查看在线实例

QQ图片20190117120816.png

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议