Skip to content

Commit 86215f8

Browse files
committed
完成 目录框的拖拉效果
1 parent 6354572 commit 86215f8

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

markdown-toc-code/css/content.css

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,34 @@
2020

2121
/* 目录栏的样式 */
2222
.div_toc{
23-
width: 90%;
23+
width: -webkit-calc(100% - 10px);
24+
height: 100%;
2425
float: left;
25-
/* */
26-
/*
2726
padding: 20px;
28-
border-radius: 3px;
29-
width: 400px;
30-
height: 85%;
31-
min-height: 200px;
32-
z-index: 999;
33-
left: 10px;
34-
top: 70px;
35-
bottom: 20px;
36-
overflow-x: hidden;
3727
overflow: auto;
28+
overflow-x: hidden;
3829
background-color: #fafbfc;
3930
border: 1px solid #d1d5da;
40-
float: right; */
41-
/* width: 400px;
42-
min-height: 200px;
43-
z-index: 999;
44-
background-color: #fafbfc;
45-
border: 1px solid #d1d5da;
46-
overflow-x: hidden;
47-
left: 10px;
48-
top: 70px;
49-
border-radius: 3px;
50-
overflow: auto;
51-
height: 85%;
52-
bottom: 100px;
53-
float: left; */
54-
/* cursor: e-resize; */
31+
5532
}
5633

5734
.div_right_bar{
58-
width:10px; background: red; cursor: e-resize; float: left;
35+
width: 10px;
36+
height: 100%;
37+
background-color: white;
38+
cursor: e-resize;
39+
float: left;
5940
}
6041

6142
.toc{
6243
position: fixed;
6344
width: 400px;
6445
min-height: 200px;
6546
z-index: 999;
66-
background-color: #fafbfc;
67-
border: 1px solid #d1d5da;
68-
padding: 20px;
69-
overflow-x: hidden;
47+
7048
left: 10px;
7149
top: 70px;
7250
border-radius: 3px;
73-
overflow: auto;
7451
height: 85%;
7552
bottom: 100px;
7653
float: left;

markdown-toc-code/js/content-script.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function init(list) {
3939
var div_right_bar = document.createElement("div"); // 这是一个 拖动bar
4040
div_right_bar.setAttribute('id', "div_right_bar");
4141
div_right_bar.setAttribute("class", "div_right_bar");
42-
div_right_bar.textContent = "bar";
42+
div_right_bar.textContent = "";
4343

4444

4545

@@ -86,18 +86,16 @@ function init(list) {
8686
return toc;
8787
}
8888

89+
8990
// 这里是绑定resize事件的方法
9091
function bindResize(el) {
9192
//初始化参数
9293
var els = document.getElementById('toc').style;
93-
9494
//鼠标的 X 和 Y 轴坐标
9595
x = 0;
96-
9796
//邪恶的食指
9897
el.onmousedown = function(e){
9998
//按下元素后,计算当前鼠标与对象计算后的坐标
100-
10199
x = e.clientX - el.offsetWidth,
102100
y = e.clientY - el.offsetHeight;
103101
console.log(x);
@@ -125,6 +123,10 @@ function bindResize(el) {
125123
function mouseMove(e) {
126124
//宇宙超级无敌运算中...
127125
els.width = e.clientX - x + 'px';
126+
els.width = e.clientX - 10 + 'px';
127+
console.log("clientX:"+e.clientX);
128+
console.log("x:"+x);
129+
128130
}
129131
//停止事件
130132
function mouseUp() {
@@ -138,10 +140,7 @@ function bindResize(el) {
138140
function(){
139141
document.removeEventListener("mousemove", mouseMove);
140142
document.removeEventListener("mouseup", mouseUp);
141-
}()
142-
//卸载事件
143-
// 这里也需要改写,你帮我看下啊。这样对吗?1
144-
143+
}()
145144
);
146145
}
147146
}

0 commit comments

Comments
 (0)