Skip to content

Instantly share code, notes, and snippets.

@ksk1015
ksk1015 / mysublimetext2shortcut
Last active December 17, 2015 18:49
sublime text 2 my chortcut memo
画像の高さと幅を更新(Update Image Size)
Winコマンド:Ctrl+U
Macショートカット:Shift + Ctrl + I
@ksk1015
ksk1015 / jquery.fn.random
Created July 8, 2013 03:01
return a random item
(function($){
$.fn.random = function(){
var index = Math.floor(Math.random() * this.length);
return this.eq(index);
};
})(jQuery);
// $("elem").random()
@ksk1015
ksk1015 / css-clearfix
Created July 10, 2013 05:23
clearfix
.clearfix {
*zoom: 1;
}
.clearfix:before,
.clearfix:after {
content: "";
clear: both;
display: table;
}
@ksk1015
ksk1015 / svgfixer.js
Created August 15, 2016 04:04 — forked from leonderijke/svgfixer.js
Fixes references to inline SVG elements when the <base> tag is in use.
/**
* SVG Fixer
*
* Fixes references to inline SVG elements when the <base> tag is in use.
* Firefox won't display SVG icons referenced with
* `<svg><use xlink:href="#id-of-icon-def"></use></svg>` when the <base> tag is on the page.
*
* More info:
* - http://stackoverflow.com/a/18265336/796152
* - http://www.w3.org/TR/SVG/linking.html
@ksk1015
ksk1015 / my-photoswipe-init.js
Created September 27, 2016 14:18
photoswipe initialize to set image size on load image
function MyPhotoswipeInit(pswpElement, PhotoSwipeUI_Default, items, options){
var pswp = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
pswp.listen('imageLoadComplete', function(index, item) {
if ( item._myLoaded ) {
return;
}
var img = document.createElement('img');
img.onload = function(){
item.w = this.naturalWidth;
@ksk1015
ksk1015 / scrollMax.js
Last active December 9, 2016 08:00
window.scrollMaxX, window.scrollMaxY polyfill, add scrollMaxX, scrollMaxY to HTMLElement.
// window.scrollMaxX, window.scrollMaxY polyfill
'scrollMaxX' in window || Object.defineProperties(window, {
scrollMaxX: {
enumerable: true,
get: function(){
return document.documentElement.scrollWidth - document.documentElement.clientWidth;
},
},
scrollMaxY: {
enumerable: true,
@ksk1015
ksk1015 / input-hansu.js
Created December 9, 2016 09:42
data-hansu属性のinputを強制的に半数字のみに変換
document.addEventListener('change', function(evt){
var elem = evt.target;
if ( elem.hasAttribute('data-hansu') ) {
elem.value = elem.value.replace(/[0-9]/g, function(s){
return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
}).replace(/\D/g, '');
}
});
@ksk1015
ksk1015 / detectMovableMouse.js
Created March 1, 2017 07:04
detect movable mouse (means a device has movable mouse pointer)
(function(){
// over 2 mousemove events fired in 300ms
var over = 2, period = 300;
var count = 0;
var timer = null;
var mousemove = function(evt){
if ( !timer ) {
@ksk1015
ksk1015 / supportSticky.js
Created July 13, 2017 00:57
detect support sticky
var supportSticky = (function(){
var el = document.createElement('div');
el.style.position = 'sticky';
if (el.style.position === 'sticky') {
return true;
}
el.style.position = '-webkit-sticky';
if (el.style.position === '-webkit-sticky') {
return true;
}
function supportWebStorage () {
if (!window.sessionStorage) {
return false;
}
try {
var key = 'supportWebStorage-' + (new Date()).getTime();
window.sessionStorage.setItem(key, 1);
window.sessionStorage.removeItem(key);
return true;
} catch(err) {