File tree 9 files changed +530
-55
lines changed 9 files changed +530
-55
lines changed Original file line number Diff line number Diff line change @@ -256,7 +256,7 @@ BFC全称 Block Formatting Context 即`块级格式上下文`,简单的说,B
256
256
}
257
257
```
258
258
259
- 图片5
259
+ ![ ] ( https://user-gold-cdn.xitu.io/2020/6/7/1728f5c2724a713f?w=302&h=192&f=jpeg&s=15299 )
260
260
261
261
设置了` vertial-align: top; ` 后:
262
262
@@ -270,13 +270,45 @@ BFC全称 Block Formatting Context 即`块级格式上下文`,简单的说,B
270
270
}
271
271
```
272
272
273
- 图片6
273
+ ![ ] ( https://user-gold-cdn.xitu.io/2020/6/7/1728f5c467fb3e50?w=296&h=186&f=jpeg&s=13657 )
274
274
275
275
276
276
277
277
### 如何解决inline-block空白问题?
278
278
279
- - ** 删除html中的空白** :不要让元素之间换行:
279
+ 原本的代码为:
280
+
281
+ ``` html
282
+ <style >
283
+ .sub {
284
+ background : hotpink ;
285
+ display : inline-block ;
286
+ }
287
+ </style >
288
+ <body >
289
+ <div class =" super" >
290
+ <div class =" sub" >
291
+ 孩子
292
+ </div >
293
+ <div class =" sub" >
294
+ 孩子
295
+ </div >
296
+ <div class =" sub" >
297
+ 孩子
298
+ </div >
299
+ </div >
300
+ </body >
301
+ ```
302
+
303
+ 效果为:
304
+
305
+ 图片1
306
+
307
+ 可以看到每个` 孩子 ` 之间都会有一个空白。` inline-block ` 元素间有空格或是换行,因此产生了间隙。
308
+
309
+ 解决办法:
310
+
311
+ - ** (1) 删除html中的空白** :不要让元素之间换行:
280
312
281
313
``` html
282
314
<div class =" super" >
@@ -290,7 +322,7 @@ BFC全称 Block Formatting Context 即`块级格式上下文`,简单的说,B
290
322
</div >
291
323
```
292
324
293
- - ** 设置负的边距** :你可以用负边距来补齐空白。但你需要调整` font-size ` ,因为空白的宽度与这个属性有关系。例如下面这个例子:
325
+ - ** (2) 设置负的边距** :你可以用负边距来补齐空白。但你需要调整` font-size ` ,因为空白的宽度与这个属性有关系。例如下面这个例子:
294
326
295
327
``` css
296
328
.sub {
@@ -301,9 +333,9 @@ BFC全称 Block Formatting Context 即`块级格式上下文`,简单的说,B
301
333
}
302
334
```
303
335
304
- - ** 给父级设置font-size: 0** :不管空白多大,由于空白跟font-size的关系 ,设置这个属性即可把空白的宽度设置为0。但是如果你的子级有字的话,也得单独给子级设置字体大小。
336
+ - ** (3) 给父级设置font-size: 0** :不管空白多大,由于空白跟 ` font-size ` 的关系 ,设置这个属性即可把空白的宽度设置为0。但是如果你的子级有字的话,也得单独给子级设置字体大小。
305
337
306
- - ** 注释** :
338
+ - ** (4) 注释** :
307
339
308
340
``` html
309
341
<div class =" super" >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -169,14 +169,14 @@ function getCookie(name) {
169
169
170
170
- ` box.onmousedown `
171
171
- ` document.onmousemove `
172
- - ` box .onmouseup`
172
+ - ` document .onmouseup`
173
173
174
174
3 . 实现的事件顺序
175
175
176
176
- 首先监听` box.onmousedown ` ,即鼠标按下` box ` 时触发的事件,记录下鼠标按下时距离屏幕上边和左边的距离,以及` box ` 距离屏幕上边和左边的距离,再用前者减去后者得到差值` distanceX ` 和` distanceY `
177
177
- 然后在此事件中监听` document.onmousemove ` 事件,记录下每次鼠标移动时距离屏幕上边和左边的距离,然后用它们减去` distanceX ` 和` distanceY ` ,再将其赋值给` box ` 的` left ` 和` top ` ,使其能跟着鼠标移动
178
178
- 不过需要考虑` box ` 距离屏幕最上面/下面/左边/右边的边界情况
179
- - 当` box .onmouseup` 的时候需要将` document.onmousemove ` 事件设置为` null `
179
+ - 当` document .onmouseup` 的时候需要将` document.onmousemove ` 事件设置为` null `
180
180
181
181
如图所示:
182
182
@@ -235,14 +235,16 @@ window.onload = function () {
235
235
box .style .left = left + ' px' ;
236
236
box .style .top = top + ' px' ;
237
237
}
238
- box .onmouseup = function () {
238
+ document .onmouseup = function () {
239
239
document .onmousemove = null ;
240
240
box .onmouseup = null ;
241
241
}
242
242
}
243
243
}
244
244
```
245
245
246
+ (感谢[ Turbo328] ( https://github.com/Turbo328 ) 指出使用` document.onmouseup ` 效果会比` box.onmouseup ` 好一些)
247
+
246
248
[ https://github.com/LinDaiDai/niubility-coding-js/issues/11 ] ( https://github.com/LinDaiDai/niubility-coding-js/issues/11 )
247
249
248
250
### 五、如何阻止冒泡和默认事件(兼容写法)
Original file line number Diff line number Diff line change
1
+ ## DD每周前端七题详解-第五期
2
+
3
+ ## 系列介绍
4
+
5
+ 你盼世界,我盼望你无` bug ` 。Hello 大家好!我是霖呆呆!
6
+
7
+ 呆呆每周都会分享七道前端题给大家,系列名称就是「DD每周七题」。
8
+
9
+ 系列的形式主要是:` 3道JavaScript ` + ` 2道HTML ` + ` 2道CSS ` ,帮助我们大家一起巩固前端基础。
10
+
11
+ 所有题目也都会整合至 [ LinDaiDai/niubility-coding-js] ( https://github.com/LinDaiDai/niubility-coding-js/issues ) 的` issues ` 中,欢迎大家提供更好的解题思路,谢谢大家😁。
12
+
13
+ 一起来看看本周的七道题吧。
14
+
15
+
16
+
17
+ ## 正题
18
+
19
+ ### 一、JS基础知识,++自增运算符
20
+
21
+ (题目提供者:[ sinnkirou] ( https://github.com/sinnkirou ) )
22
+
23
+ ```
24
+ var a =10;
25
+ var b = ++a;
26
+ => a=10; b=11
27
+
28
+ a,b应该都是11
29
+ ```
30
+
31
+
32
+
33
+
34
+
35
+ ## 后语
36
+
37
+ 你盼世界,我盼望你无` bug ` 。这篇文章就介绍到这里。
38
+
39
+ 您每周也许会花` 48 ` 小时的时间在工作💻上,会花` 49 ` 小时的时间在睡觉😴上,也许还可以再花` 20 ` 分钟的时间在呆呆的7道题上,日积月累,我相信我们都能见证彼此的成长😊。
40
+
41
+ 什么?你问我为什么系列的名字叫` DD ` ?因为` 呆呆 ` 呀,哈哈😄。
42
+
43
+ 喜欢** 霖呆呆** 的小伙还希望可以关注霖呆呆的公众号 ` LinDaiDai ` 或者扫一扫下面的二维码👇👇👇。
44
+
45
+ ![ ] ( https://user-gold-cdn.xitu.io/2020/6/17/172c12220c3a29a1?w=900&h=500&f=gif&s=1632550 )
46
+
47
+ 我会不定时的更新一些前端方面的知识内容以及自己的原创文章🎉
48
+
49
+ 你的鼓励就是我持续创作的主要动力 😊。
You can’t perform that action at this time.
0 commit comments