Skip to content

Instantly share code, notes, and snippets.

View sabrinaluo's full-sized avatar
loading...

HiiTea sabrinaluo

loading...
View GitHub Profile
@sabrinaluo
sabrinaluo / gist:440812106396219f1523
Last active August 29, 2015 14:11
find element index in array; check whether element is in array
var array = ["lily", "tom", "lucy"];
var ele1 = "lily";
var ele2 = "lucy";
var ele3 = "jack";
array.indexOf(ele1); // return 0
array.indexOf(ele2); // return 2
array.indexOf(ele3); //return -1; NOTE: element is not in the array if return -1
@sabrinaluo
sabrinaluo / gist:6fa9fd7697bfbdfc2acf
Created December 9, 2014 04:44
find index of active element
<ul>
<li>item1</li>
<li class="active">item2</li>
<li>item3</li>
</ul>
<script>
$(ul).find(".active").index(); //return 1
</script>
@sabrinaluo
sabrinaluo / img_radius.html
Last active August 29, 2015 14:11
img round, round corner, css图片圆角
<style>
img{
border-radius:10px;
}
</style>
<img src="xx.jpg">
@sabrinaluo
sabrinaluo / jq_elementSearch.js
Last active August 29, 2015 14:11
查找元素
//查找同级元素
$("#id").next(); // 下一个同级元素
$("#id").prev(); // 前一个
$("#id").nextAll("div"); // 所有该元素之后的同级div元素
$("#id").prevAll("div");
$("#id").prevAll("div").andSelf(); //所有该元素之前的同级div元素及该元素本身
@sabrinaluo
sabrinaluo / img_rounded.html
Created December 16, 2014 07:59
css img rounded 图片 圆形
<style>
div{
height:100px;
width:100px; /*宽高必须相等*/
overflow:hidden; /*隐藏超出div的部分*/
border-radius:50%;/*圆角为宽高的50%*/
}
</style>
<div>
@sabrinaluo
sabrinaluo / gist:18be8a2e7e42e2cd2793
Created December 31, 2014 09:21
whether an element has children
$("#ele").children().length>0; // if has children return true
@sabrinaluo
sabrinaluo / gist:6779c0760d800504615c
Created January 6, 2015 06:51
jquery first child
<div>
<p>123</p>
<p>321</p>
<p>456</p>
<p>789</p>
</div>
<script>
$("div p:first-child") //return <p>123</p>
</script>
@sabrinaluo
sabrinaluo / gist:8bd89b0e509c7a73f968
Created January 6, 2015 11:08
handlebars.js array index
{{#each data}}
<div>{{@index}}</div> <!-- start from 0-->
<div>{{this}}</div> <!-- "aa"-->
{{/each}}
<script>
var data = ["aa","bb"]
</script>
@sabrinaluo
sabrinaluo / .travis.yml
Created December 28, 2015 05:05
.travis.yml for hexo blog
language: node_js
node_js:
- '4.0'
branches:
only:
- master
before_install:
- openssl aes-256-cbc -K $encrypted_e011a6d7eebf_key -iv $encrypted_e011a6d7eebf_iv -in .travis/id_rsa.enc -out ~/.ssh/id_rsa -d
- chmod 600 ~/.ssh/id_rsa
- eval $(ssh-agent)
@sabrinaluo
sabrinaluo / object-isEmpty.js
Last active December 30, 2015 07:12
{} isEmpty()
function isEmpty(obj) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
}