Justin's Words


  • Home

  • About

  • Archives
Justin's Words

CSS Flexbox

Posted on 2015-08-27 | In Front-End |

有一个容器:

1
2
3
4
5
6
7
<div class="container">
<item class="item"></item>
<item class="item"></item>
<item class="item"></item>
<item class="item"></item>
<item class="item"></item>
</div>
Read more »
Justin's Words

CSS 限制多行为省略号

Posted on 2015-08-27 | In Front-End |

现在有如下 HTML:

1
2
3
<div class="module">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</div>

设置多行限制为省略号如下:

1
2
3
4
5
6
7
8
9
10
.module {
width: 250px;
overflow: hidden;
}

.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}

设置宽度限制为省略号如下:

1
2
3
4
5
6
.module {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Justin's Words

JavaScript 判断 URL

Posted on 2015-08-27 | In Front-End |
1
2
3
var URL_REGEXP = /^(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?$/;
var url = "https://g.taobao.com/brand_detail.htm?navigator=all&_input_charset=utf-8&q=%E7%94%B7%E5%A3%AB%E8%A1%AC%E8%A1%AB%E8%8B%B1%E4%BC%A6%E6%AC%BE&spm=5148.1292865.a31d2.2.NiXIQv";
URL_REGEXP.test(url); // true
Read more »
Justin's Words

JavaScript 判断对象是否为空

Posted on 2015-08-05 | In Front-End |

来自:Is object empty?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Speed up calls to hasOwnProperty
var hasOwnProperty = Object.prototype.hasOwnProperty;

function isEmpty(obj) {

// null and undefined are "empty"
if (obj == null) return true;

// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length > 0) return false;
if (obj.length === 0) return true;

// Otherwise, does it have any properties of its own?
// Note that this doesn't handle
// toString and valueOf enumeration bugs in IE < 9
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}

return true;
}

underscore.js 对此有专门的函数判断,为 _.isEmpty()。

Justin's Words

AngularJS $watch()

Posted on 2015-07-29 | In Front-End |

理解 AngularJS 的 $watch()。

$watch(watchExpression<string|Function(scope)>, listener, [objectEquality])

$watch() 可以接受两个函数作为参数,第一个参数数返回监控的 $scope 的变量,第二个函数操作该变量的旧值和新值,第三个参数是可选的,类型为 Boolean,true 则表明第一个参数返回的是一个对象,默认为 false,结构:

1
2
3
4
$scope.$watch(function (scope){
return scope.variable;
}, function (newValue, oldValue) {
});
Read more »
Justin's Words

JavaScript 检测汉字

Posted on 2015-07-27 | In Front-End |
1
2
3
4
function isChinese(word) {
var re = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi;
return re.test(word);
}
Justin's Words

为 Lollipop 上 Chrome 设置相应颜色状态栏

Posted on 2015-07-19 | In Front-End |

未设置状态栏变色和设置后的截图如下:

chrome

Read more »
Justin's Words

Java Comparator

Posted on 2015-06-11 | In Java |

上代码:

Read more »
Justin's Words

使用有道翻译 api 做 Chrome 扩展

Posted on 2015-06-10 | In Front-End |

花了点时间做了个 Chrome 扩展(Github),用的是有道翻译 api。

Read more »
Justin's Words

Java Collections

Posted on 2015-06-05 | In Java |

惯例,先上代码:

Read more »
1234…11
Justin Young

Justin Young

You Deserve A Better Life

107 posts
15 categories
54 tags
RSS
Github Twitter
© 2014 - 2019 Justin Young
Powered by Hexo
Theme - NexT.Mist