Skip to content

Instantly share code, notes, and snippets.

View JoeKeikun's full-sized avatar

Joe Keikun JoeKeikun

View GitHub Profile
@JoeKeikun
JoeKeikun / what-forces-layout.md
Created August 25, 2017 03:36 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@JoeKeikun
JoeKeikun / grayscale.js
Created November 24, 2015 05:42
js 装换灰度图
var canvasData = context.getImageData(0, 0, canvas.width, canvas.height);
// 转换灰度图
for (var x = 0; x < canvasData.width; x++) {
for (var y = 0; y < canvasData.height; y++) {
// Index of the pixel in the array
var idx = (x + y * canvasData.width) * 4;
var r = canvasData.data[idx + 0];
var g = canvasData.data[idx + 1];
var b = canvasData.data[idx + 2];
@JoeKeikun
JoeKeikun / JS常用正则表达式
Created April 10, 2015 05:06
JS常用正则表达式
/*
用途:检查输入的Email信箱格式是否正确
输入:strEmail:字符串
返回:如果通过验证返回true,否则返回false
*/
function checkEmail(strEmail)
{
//var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
var emailReg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
if ( emailReg.test(strEmail) ) {
@JoeKeikun
JoeKeikun / getSelectedText
Created April 3, 2015 07:25
get selected text
$('div').mouseup(function() {
alert(getSelectedText());
});
function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
@JoeKeikun
JoeKeikun / ratio_div_by_css
Created March 26, 2015 12:55
Use CSS to Specify the Aspect Ratio DIV
[HTML]
<div class='box'>
<div class='content'>Aspect ratio of 1:1</div>
</div>
[CSS]
.box{
position: relative;
@JoeKeikun
JoeKeikun / water drop
Created November 11, 2014 02:26
通过贝塞尔曲线来描画液体的拉扯感线条
var waterdrop = function() {};
/**
* 通过入参,计算组成水滴形状的两条贝塞尔曲线控制点.
*
* @method getBezierPoints
*
* @param {Number} x 起始点x轴坐标
* @param {Number} y 起始点x轴坐标
* @param {Number} deltaX 起始点x轴上的间距
@JoeKeikun
JoeKeikun / timing function
Created November 11, 2014 02:23
jquery ui提取出来的时间处理函数
var timingfunction = {};
/**
* linear 函数
*
* @param {Number} p 正常百分比值
* @return {Number} 换算后的结果
*/
timingfunction.linear = function(p) {
return p;
@JoeKeikun
JoeKeikun / input_cursor_color
Last active June 7, 2022 12:08
How to change <input> input cursor color by css (webkit)
When I developed an app for ios by phonegap, I had a trouble in changing the <input> input cursor color.
but now, there is a solution for it:
---------------
<style>
input {
color: rgb(60, 0, 248); /* change [input cursor color] by this*/
text-shadow: 0px 0px 0px #D60B0B; /* change [input font] by this*/
-webkit-text-fill-color: transparent;