Skip to content

Instantly share code, notes, and snippets.

@madrobby
madrobby / scrolltotop.annotated.js
Last active April 9, 2022 00:06
scrolltotop, a Zepto plugin to scroll things to the top (and any other vertical scroll position)
// Usage: $(element).scrollToTop([position])
;(function($){
// only allow one scroll to top operation to be in progress at a time,
// which is probably what you want
var scrollToTopInProgress = false
$.fn.scrollToTop = function(position){
var $this = this,
targetY = position || 0,
@madrobby
madrobby / scrolltotop.js
Created January 13, 2014 21:12
Scroll to top plugin for Zepto 1.1
;(function($){
$.fn.scrollToTop = function(){
var $this = $(this),
initialY = $this.scrollTop(),
start = +new Date,
speed = Math.min(750, Math.min(1500, initialY)),
now,
t, y
if (initialY == 0) return
Using worker: worker-linux-6-2.bb.travis-ci.org:travis-linux-1
git.1
$ git clone --depth=50 --branch=master git://github.com/madrobby/zaru.git madrobby/zaru
Cloning into 'madrobby/zaru'...
remote: Counting objects: 94, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 94 (delta 46), reused 80 (delta 32)
Receiving objects: 100% (94/94), 10.89 KiB, done.
Resolving deltas: 100% (46/46), done.
$ cd madrobby/zaru
URLcrypt.key = '...'
URLcrypt.encrypt('chunky bacon!')
# => "sgmt40kbmnh1663nvwknxk5l0mZ6Av2ndhgw80rkypnp17xmmg5hy"
URLcrypt.decrypt('sgmt40kbmnh1663nvwknxk5l0mZ6Av2ndhgw80rkypnp17xmmg5hy')
# => "chunky bacon!"
Zaru.sanitize! " what\ēver//wëird:user:înput:"
# => "whatēverwëirduserînput"
Ponymizer.new.gimmie_a_pony!
# => "Sunshine Splash"
Project names and sort order:
aawkward
åberaber
Abernein
Internally, they should be sorted with lower-case, normalized, accent-free versions:
aawkward
aberaber
abernein
$(window).on('online', online)
$(window).on('offline', offline)
// iOS 7-like panel animation using Zepto
// this is a bit simplified, but it's a good start
var PANEL_SPEED = 650,
PANEL_EASING = 'cubic-bezier(0.23,1,0.32,1)'
$('#panel_to_slide_out').animate({
translateX: '-50%', opacity: 1 }, PANEL_SPEED, PANEL_EASING)
$('#panel_to_slide_in').animate({
translateX: '0%', opacity: 1 }, PANEL_SPEED, PANEL_EASING)
data URL with svg+xml:
data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='1' height='1'><rect fill='#ff0000' x='0' y='0' width='1' height='0.5'/></svg>
data URL with svg+json:
data:image/svg+json;utf8,{"width":1,"height":1,"svg":[{"rect":{"fill":"#ff0000","x":0,"y":0,"width":1,"height":0.5}}]}