Skip to content

Instantly share code, notes, and snippets.

// ucs-2 string to base64 encoded ascii
function utoa(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}
// base64 encoded ascii to ucs-2 string
function atou(str) {
return decodeURIComponent(escape(window.atob(str)));
}
// Usage:
utoa('✓ à la mode'); // 4pyTIMOgIGxhIG1vZGU=
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>getUserMedia</title>
</head>
<body>
<video id="camera"></video>
<script>
document.addEventListener('DOMContentLoaded', onDOMContentLoaded, false);
@rainyjune
rainyjune / form-serialization.html
Created October 31, 2016 06:27
Form Serialization
<!doctype html>
<html>
<head>
<title>Form Serialization</title>
</head>
<body>
<form action="form.php" method="post">
<input type="hidden" name="hiddeninput" value="hidden value" />
Name:<input type="text" name="username" /><br />
Pass:<input type="password" name="userpassword" /> <br />
@rainyjune
rainyjune / gist:94ed1aaf1cdaa4bf679e
Created August 21, 2014 06:30
图片无缝滚动
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Js图片无缝滚动</title>
<style type="text/css">
body{
background:gray;
}
#wrap{
@rainyjune
rainyjune / gist:9a8bad1efa7e97c3b17f
Last active August 29, 2015 14:05
CSS dimensions
/* Firefox /NS6 properties for determining browser dimension */
window.innerHeight; // Returns the physical height of the browser screen
window.innerWidth; // Returns the pyhsical widht of the browser screeen
/* IE 4+ properties for determining browser dimension */
document.body.clientWidht; // Returns physical width of the browser screen
document.body.clientHeight; // Returns the physical height of the browser screen
/* Firefox / NS6+ properties for determining DSOC */
window.pageXOffset; // Returns the x coordinate of the DSOC
@rainyjune
rainyjune / blank.gif
Last active August 29, 2015 13:56
CSS 视差效果
blank.gif
@rainyjune
rainyjune / gist:6332821
Created August 25, 2013 09:00
一个常用的针对移动网页优化过的页面的 viewport meta 标签大致如下:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
@rainyjune
rainyjune / blue.css
Last active December 18, 2015 14:09
进度条
#loadbar {
width: 280px;
background-color: #000;
border: 1px solid #000;
}
#bar {
display: block;
font-family: arial;
font-size: 12px;
background-color: #00d0ff;
<!DOCTYPE html>
<html>
<head>
<title>Window onload event</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>TODO write content</div>
<img src="1.jpg" alt="1.jpg" width="200" height="200" id="pic"><br>
<script src="slide.js"></script>
@rainyjune
rainyjune / gist:5747933
Created June 10, 2013 10:52
onload function
function addOnload(newFunction) {
var oldOnload = window.onload;
if(typeof oldOnload === "function") {
alert("OldOnload is not null");
window.onload = function() {
if (oldOnload) {
alert("OLD found, Let do OLD");
oldOnload();
}
alert("Do new function");