Skip to content

Instantly share code, notes, and snippets.

View sundaycrafts's full-sized avatar

sundaycrafts

View GitHub Profile
@sundaycrafts
sundaycrafts / preventPullToRefresh.js
Created May 23, 2015 06:16
prevent pull to refresh mobile chrome feature
/**
* inspired by jdduke (http://jsbin.com/qofuwa/2/edit)
*/
var preventPullToRefresh = (function preventPullToRefresh(lastTouchY) {
lastTouchY = lastTouchY || 0;
var maybePrevent = false;
@sundaycrafts
sundaycrafts / scrollableElement.js
Last active August 29, 2015 14:21
scrollableElement.js
// http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
function scrollableElement(els) {
for(var i = 0, len = arguments.length; i < len; i++) {
var el = arguments[i],
$scrollElement = $(el);
if($scrollElement.scrollTop() > 0) {
return el;
} else {
$scrollElement.scrollTop(1);
@sundaycrafts
sundaycrafts / responsiveYoutubeVideo.scss
Last active August 29, 2015 14:21
css: responsive youtube video
http://h2ham.net/youtube-responsive
.youtube {
position: relative;
width: 100%;
padding-top: 56.25%; // it is aspect ratio. padding respect to the width
iframe {
position: absolute;
top: 0;
left: 0;
@sundaycrafts
sundaycrafts / getLineHeight.scss
Created May 28, 2015 09:05
sass: getLineHeight function
$FontSize: 14px;
$LineHeight: $FontSize * 1.5;
@function getLineHeight($fontSize) {
$height: $LineHeight;
@while $height < $fontSize {
$height: $height + $height;
}
@return $height;
}
@sundaycrafts
sundaycrafts / vCentering.scss
Created May 28, 2015 09:07
sass: vertical centering
%vCentering {
// https://css-tricks.com/centering-in-the-unknown/
text-align: center;
white-space: nowrap;
overflow-x: hidden;
&:before {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
@sundaycrafts
sundaycrafts / regex.pl
Last active August 29, 2015 14:22
useful regular expression
# get 4 spaces indents(it is not works perfectly but enough)
/(?<!\S) {4}/
# erace padding text such as ctrl char when logging bash log by [script] command
s/((?![\n\t])[[:cntrl:]])|(\[.*?(m|k))//g
@sundaycrafts
sundaycrafts / ajax.html
Created June 4, 2015 11:17
js: AJAX load html very simple example
<h1>Hello world!</h1>
@sundaycrafts
sundaycrafts / data.json
Created June 6, 2015 04:16
js: AJAX load JSON very simple example
{
"name": "sundaycrafts",
"age": 18,
"gender": "male",
"msg": "<h1>Hello World!</h1>"
}
$maxWidth: 1330px
$col: 100px/$maxWidth * 100%
$margin: 10px/$maxWidth * 100%
@mixin col($contentCol:1, $marginCol-left:0, $marginCol-right:0)
width: $col*$contentCol + $margin*($contentCol - 1)
margin-left: ($col+$margin)*$marginCol-left + $margin
margin-right: ($col+$margin)*$marginCol-right + $margin
@sundaycrafts
sundaycrafts / load.ts
Last active September 5, 2015 14:32
jq, js: Load HTML fragment with JQuery ajax() without $.load()
// この実装は$.load()に限りなく近い
// http://james.padolsey.com/jquery/#v=2.1.3&fn=jQuery.fn.load
// http://stackoverflow.com/questions/16885538/how-to-load-an-html-fragment-with-jquery-ajax
$.ajax({
url: 'page.html',
dataType: 'html'
}).done(responsText =>
// 空のdiv要素に追加
var $el = $('<div>').append($.parseHTML(responsText)).find('.selector');
// この処理は逐次的に行う必要がある。