Skip to content

Instantly share code, notes, and snippets.

View cssoul's full-sized avatar
🎯
Focusing

達也 cssoul

🎯
Focusing
  • -
View GitHub Profile
@cssoul
cssoul / gist:5430148
Last active December 16, 2015 11:49
遍历元素, 点击获取索引值
<!--HTML-->
<ul id="J_Item">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
</ul>
<!--JavaScript-->
<script>
@cssoul
cssoul / gist:5457019
Created April 25, 2013 02:18
让博文中的图片不超出盒子外面,给以自适应宽度
<!--HTML-->
<div id="blog_wrap">
<div class="side"></div>
<div class="post">
<img src="/" alt="图片" style="width:900px;height:100px;"/>
</div>
</div>
<!--JavaScript-->
<script>
@cssoul
cssoul / gist:5479602
Last active March 4, 2022 03:33
获取字符串的字节长度
new function(s)
{
if(!arguments.length||!s) return null;
if(""==s) return 0;
var l=0;
for(var i=0;i<s.length;i++)
{
if(s.charCodeAt(i)>255)
{
l+=2;
@cssoul
cssoul / gist:5479661
Created April 29, 2013 04:12
去掉数组中的重复元素
Array.prototype.strip=function()
{
if(this.length<2) return [this[0]]||[];
var arr=[];
for(var i=0;i<this.length;i++)
{
arr.push(this.splice(i--,1));
for(var j=0;j<this.length;j++)
{
if(this[j]==arr[arr.length-1])
@cssoul
cssoul / gist:5479691
Created April 29, 2013 04:24
获取字符串中出现次数最多的字符以及出现次数
var maxchar = function(s){
var o = {},t = [0,''];
for(var i = 0 , l = s.length; i < l ; i++){
if(o[s[i]]){
o[s[i]] += 1;
if(o[s[i]] > t[0]){
t[0] = o[s[i]];
t[1] = s[i];
}
}else{
@cssoul
cssoul / gist:5479940
Created April 29, 2013 05:58
去除字符串的前后空格
String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
var str = ' abcdefg ';
console.log(str.trim());
@cssoul
cssoul / gist:5483396
Last active December 16, 2015 19:10
Flexbox相关知识
/*
* Flexbox 设置为伸缩容器(包括伸缩容器和伸缩项目)
* (flex /inline-flex )
*/
display: -webkit-flex;
display: flex;
/*
@cssoul
cssoul / gist:5483564
Last active December 16, 2015 19:11
Flexbox实现元素水平、垂直局中
<!--HTML-->
<div class="flex-container">
<div class="flex-item">I'm centered!</div>
</div>
<!--CSS-->
<style>
.flex-container {
display: -webkit-flex;
display: flex;
@cssoul
cssoul / gist:5487485
Last active December 16, 2015 19:49
JavaScript数组常用操作
/*建立数组*/
var Obj = new Array();
var Obj = new Array(size);
var Obj = new Array(element0, element1, ..., elementn);
/*遍历数组*/
for (var i in Obj)
{
console.log(Obj[i]+",");
@cssoul
cssoul / gist:5612261
Created May 20, 2013 13:36
利用径向渐变实现 不规则渐变阴影
.top-shadow {
width: 200px;
height: 200px;
}
.top-shadow:after {
content: "";
width: 100%;
height: 8px;
display: block;