Skip to content

Instantly share code, notes, and snippets.

@Dzinlife
Dzinlife / jQuery check hover staue
Last active December 24, 2015 21:09
jQuery check hover staue
if($(element).is(':hover')) { do something }
function handler( event ) {
var target = $( event.target );
}
function preventMacBackFwdGesture(element, scrollable) {
if (scrollable === undefined) {
var scrollable = true;
};
$(element).each(function () {
var $this = $(this);
var scrollDirection;
$this.mousewheel(function(event, delta, deltaX, deltaY) {
if (Math.abs(deltaX) < Math.abs(deltaY)) {
scrollDirection = "vertical";
Firefox 14.0.1
window.retina => undefined
window.devicePixelRatio => undefined
Chrome 21.0.1180.57
window.devicePixelRatio => 2
window.retina => undefined
Safari 6.0 (8536.25)
window.retina => true
var MobileDetect = function() {
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
@Dzinlife
Dzinlife / gist:0eb9b949e698d23ae19d
Last active November 5, 2017 09:26
Low pass filter
const double ALPHA = 0.05;
resultSpeed = ALPHA * currentSpeed + (1.0 - ALPHA) * resultSpeed;
var clickOrTouch = (('ontouchend' in window)) ? 'touchend' : 'click';
$('#element').on(clickOrTouch, function() {
// do something
});
define(('__proto__' in {} ? ['zepto'] : ['jquery']), function($) {
return $;
});
function randomArray(array){
function swap(obj, a, b) {
var tmp = obj[a];
obj[a] = obj[b];
obj[b] = tmp;
}
var length = array.length;
var rand = function(){
return Math.round(Math.random() * (length - 1));
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="./css/index.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#enzan").click( function() {
var a = $("#start").val();
var n = 9
var r = n/2
function range(i){
var left = -r + i
var right = -r + i + 1
if( left < - r ){
left = -r
}