Skip to content

Instantly share code, notes, and snippets.

View tsmd's full-sized avatar

Shimada Takayuki tsmd

View GitHub Profile
/**
* 画像の回転を取得する
* @returns {number} 回転を表す数字。正しく表示するために数字に応じて以下の処理をする:
* 1: 何もしない
* 2: 左右反転
* 3: 180度回転
* 4: 180度回転し、左右反転
* 5: 時計回りに90度回転し、左右反転
* 6: 時計回りに90度回転
* 7: 時計回りに270度回転し、左右反転
/**
* 引数を起点に兄弟要素、親の兄弟要素、さらに親の兄弟要素、…を取得する
* @param {Element} baseElement
* @return {[Element]} 対象となるHTML要素
*/
export function collectAllSiblings(baseElement) {
const targets = []
let current = baseElement
while (current && current !== document.body) {
const siblings = Array.from(current.parentNode.children)
@tsmd
tsmd / _textarea.scss
Last active May 30, 2019 15:10
Cool textarea
@charset "UTF-8";
.Textarea {
@at-root {
& {
position: relative;
color: inherit;
font-size: rem(16px);
line-height: 1.8;
}
@tsmd
tsmd / _text-input.scss
Created May 29, 2019 00:38
Cool text input
@charset "UTF-8";
.TextInput {
@at-root {
& {
width: 100%;
height: rem(40px);
padding: 0 rem(14px);
border: 0;
color: inherit;
@tsmd
tsmd / _radio.scss
Created May 29, 2019 00:32
Cool radio button
@charset "UTF-8";
.Radio {
@at-root {
& {
position: relative;
z-index: 0;
display: inline-flex;
justify-content: flex-start;
align-items: baseline;
@tsmd
tsmd / _checkbox.scss
Created May 29, 2019 00:30
Cool checkbox
@charset "UTF-8";
.Checkbox {
@at-root {
@function checked-icon($color: #fff) {
$color: '' + $color;
$color: '%23' + str-slice($color, 2);
@return 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M9%2016.17L4.83%2012l-1.42%201.41L9%2019%2021%207l-1.41-1.41z%22%20fill%3D%22#{$color}%22%2F%3E%3C%2Fsvg%3E';
}
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" id="meta-viewport">
<script>
!function() {
var viewport = document.getElementById('meta-viewport');
function onResize () {
var value = window.outerWidth < 375 ? "width=375" : "width=device-width,initial-scale=1,shrink-to-fit=no";
if (viewport.getAttribute('content') !== value) {
viewport.setAttribute('content', value);
}
}
@tsmd
tsmd / smooth-scroll-2.css
Last active October 27, 2018 17:03
FLIP implementation of smooth scrolling supporting some fixed elements
.smooth-scroll {
transition: transform 0.5s ease-out !important;
}
.smooth-scroll-fixed {
display: none !important;
}
@tsmd
tsmd / smooth-scroll.css
Last active October 27, 2018 08:34
FLIP implementation of smooth scrolling https://aerotwist.com/blog/flip-your-animations/
.smooth-scroll {
transition: transform .5s ease-out;
}
@tsmd
tsmd / responsive-table.js
Created March 28, 2018 13:19
Basic idea of simple responsive-table
$.fn.responsiveTable = (function() {
var $window = $(window);
return function() {
var $el = this;
var $table = this.find('>table');
var onResize = function() {
var width = $table.outerWidth();
var height = $table.outerHeight();
var $parent = $el.parent();
var containerWidth = $parent.width();