Skip to content

Instantly share code, notes, and snippets.

View benjamingsmith's full-sized avatar
🦾

Benjamin Smith benjamingsmith

🦾
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function deviceDetection() {
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)) {
device = 'mobile';
} else {
@benjamingsmith
benjamingsmith / inifinity_scroll.js
Last active August 29, 2015 14:10
Infinity Scroll
var killScroll = false;
$(container).bind('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight && killScroll == false) {
// whatever you want to do when bottom is reached
killScroll = true;
// to prevent more loading
setTimeout(function(){killScroll = false}, 2000);
}
}
@benjamingsmith
benjamingsmith / center-mixins.scss
Last active February 16, 2017 01:07
Center items with SASS mixins
// to use: @include centerCenter;
// make sure the element has position: absolute, relative or fixed
@mixin centerCenter {
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
@benjamingsmith
benjamingsmith / randomize.js
Last active October 15, 2015 18:09
Choose a random item from an array
$.rand = function(arg) {
if ($.isArray(arg)) {
return arg[$.rand(arg.length)];
} else if (typeof arg === "number") {
return Math.floor(Math.random() * arg);
} else {
return 4;
}
}
@benjamingsmith
benjamingsmith / headingSmoothing.js
Last active August 29, 2015 13:56
Smooth Heading
var currentHeading = 0;
var newHeading = 0;
var heading = 0;
var headingCatchSmooth = 0; //catch up smoothly to the heading value;
var headingCatchSmoothSlowly = 0;
function updateFeet(){
var diffAngle = heading - headingCatchSmooth;
//console.log("heading: "+ heading);