jQuery练习_新浪微博

  1. jQuery练习_新浪微博
    1. 完成效果图
    2. 主体结构
      1. index.css
      2. index.js
      3. index.html
    3. 好好学习,努力挣钱

jQuery练习_新浪微博

完成效果图

完成效果图

主体结构

主体结构图
背景图
文本框
评价
输入框
左边栏
右边栏
上边栏

index.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
body{
background: url("../images/body_bg.jpg") no-repeat center 0;
}
.nav{
width: 100%;
height: 48px;
}
.nav>img{
width: 100%;
}
.content{
width: 1000px;
height: auto;
overflow: hidden;
background: #ebdbd4;
margin: 200px auto 0 auto;
}
.content>.left{
float: left;
width: 150px;
}
.content>.right{
float: right;
width: 240px;
}
.content>.center{
float: left;
width: 600px;
height: 168px;
background: url("../images/comment.png") no-repeat 0 0;
background-size: 600px 168px;
}
.center>.comment{
width: 570px;
height: 73px;
margin-top: 45px;
margin-left: 15px;
/*background: red;*/
resize: none;
border: none;
outline: none;
}
.center>.send{
width: 82px;
height: 30px;
margin-top: 4px;
margin-left: 506px;
border: none;
background: #fd8040;
color: white;
}
.content>.messageList{
width: 600px;
background: white;
float: left;
}
.messageList>.info{
padding: 10px 20px;
border-bottom: 2px solid #ccc;
}
.info>.infoText{
line-height: 25px;
margin-bottom: 10px;
}
.info>.infoOperation{
width: 100%;
overflow: hidden;
}
.infoOperation>.infoTime{
float: left;
font-size: 13px;
color: #ccc;
}
.infoOperation>.infoHandle{
float: right;
font-size: 13px;
}
.infoHandle>a{
text-decoration: none;
color: #ccc;
background: url("../images/icons.png") no-repeat 0 0;
padding-left: 25px;
margin-left: 10px;
}
.infoHandle>a:nth-child(2){
background-position: 0 -17px;
}
.infoHandle>a:nth-child(3){
background-position: 0 -33px;
}
.page{
width: 1000px;
height: 40px;
background: #9f5024;
margin: 0 auto;
text-align: right;
padding: 10px;
box-sizing: border-box;
}
.page>a{
text-decoration: none;
display: inline-block;
width: 20px;
height: 20px;
border: 1px solid #ccc;
text-align: center;
line-height: 20px;
color: #2b2b2b;
}

index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$(function () {
// 0.监听内容的时时输入
$("body").delegate(".comment","propertychange input", function () {
// 判断是否输入了内容
if($(this).val().length > 0){
// 让按钮可用
$(".send").prop("disabled", false);
}else{
// 让按钮不可用
$(".send").prop("disabled", true);
}
});
// 1.监听发布按钮的点击
$(".send").click(function () {
// 拿到用户输入的内容
var $text = $(".comment").val();
// 根据内容创建节点
var $weibo = createEle($text);
// 插入微博
$(".messageList").prepend($weibo);
});

// 2.监听顶点击
$("body").delegate(".infoTop", "click", function () {
$(this).text(parseInt($(this).text()) + 1);
});
// 3.监听踩点击
$("body").delegate(".infoDown", "click", function () {
$(this).text(parseInt($(this).text()) + 1);
});
// 4.监听删除点击
$("body").delegate(".infoDel", "click", function () {
$(this).parents(".info").remove();
});

// 创建节点方法
function createEle(text) {
var $weibo = $("<div class=\"info\">\n" +
" <p class=\"infoText\">"+text+"</p>\n" +
" <p class=\"infoOperation\">\n" +
" <span class=\"infoTime\">"+formartDate()+"</span>\n" +
" <span class=\"infoHandle\">\n" +
" <a href=\"javascript:;\" class='infoTop'>0</a>\n" +
" <a href=\"javascript:;\" class='infoDown'>0</a>\n" +
" <a href=\"javascript:;\" class='infoDel'>删除</a>\n" +
" </span>\n" +
" </p>\n" +
" </div>");
return $weibo;
}

// 生成时间方法
function formartDate() {
var date = new Date();
// 2018-4-3 21:30:23
var arr = [date.getFullYear() + "-",
date.getMonth() + 1 + "-",
date.getDate() + " ",
date.getHours() + ":",
date.getMinutes() + ":",
date.getSeconds()];
return arr.join("");

}
});

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>新浪微博</title>
<link rel="stylesheet" href="css/index.css">
<script src="js/jquery-1.12.4.js"></script>
<script src="js/index.js"></script>
</head>
<body>
<div class="nav">
<img src="images/nav.png" alt="">
</div>

<div class="content">
<img src="images/left.png" alt="" class="left">
<div class="center">
<textarea class="comment"></textarea>
<input type="button" value="发布" class="send" disabled>
</div>
<img src="images/right.png" alt="" class="right">
<div class="messageList"></div>
</div>
<div class="page">
<a href="javascript:;">1</a>
<a href="javascript:;">2</a>
<a href="javascript:;">3</a>
</div>
</body>
</html>

好好学习,努力挣钱

手头紧


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 2113132982@qq.com

文章标题:jQuery练习_新浪微博

文章字数:823

本文作者:南邮石磊

发布时间:2020-07-24, 00:59:58

最后更新:2020-08-06, 00:33:16

原始链接:https://southpost.github.io/2020/07/24/jQuery%E7%BB%83%E4%B9%A0_%E6%96%B0%E6%B5%AA%E5%BE%AE%E5%8D%9A/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏