Skip to content

Instantly share code, notes, and snippets.

网页可见区域宽: document.body.clientWidth;
网页可见区域高: document.body.clientHeight;
网页可见区域宽: document.body.offsetWidth (包括边线的宽);
网页可见区域高: document.body.offsetHeight (包括边线的宽);
网页正文全文宽: document.body.scrollWidth;
网页正文全文高: document.body.scrollHeight;
网页被卷去的高: document.body.scrollTop;
网页被卷去的左: document.body.scrollLeft;
网页正文部分上: window.screenTop;
网页正文部分左: window.screenLeft;
@plilion
plilion / js
Created August 25, 2015 02:41
iphone微信修改title
var $body = document.body;
document.title = title || document.title;
var $iframe = document.createElement('iframe');
$iframe.src = '/favicon.ico';
$iframe.onload = function(){
setTimeout(function(){
$iframe.onload = function(){};
$body.removeChild($iframe);
},0)
};
box.style.textAlign = "justify";
box.style.letterSpacing = '-.15em';
box.innerHTML = box.innerHTML.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '').split("").join(" ").replace(/\s{3}/g, "   ");
在iPhone下,返回
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2
在Android下,返回
Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255
@plilion
plilion / scal
Created June 3, 2015 01:14
自适应
//屏幕 适配
var phoneWidth;
function mobileMeta() {
phoneWidth = parseInt(window.screen.width);
var phoneScale = phoneWidth / 640;
var ua = navigator.userAgent;
if (/Android (\d+\.\d+)/.test(ua)) {
var version = parseFloat(RegExp.$1);
if (version > 2.3) {
document.write('<meta name="viewport" content="width=640, minimum-scale = ' + phoneScale + ', maximum-scale = ' + phoneScale + ', target-densitydpi=device-dpi">');
@plilion
plilion / slider
Created June 1, 2015 01:09
轮播图 基本架构
/**
* Unslider by @idiot and @damirfoy
* Contributors:
* - @ShamoX
*
*/
(function($, f) {
var Unslider = function() {
// Object clone
@plilion
plilion / meta
Created May 29, 2015 07:47
about meta
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 指示IE以目前可用的最高模式显示内容
<meta http-equiv="X-UA-Compatible" content="IE=Emulate IE7" />指示IE使用 <!DOCTYPE> 指令确定如何呈现内容。标准模式指令以IE7 标准模式显示,而 Quirks 模式指令以 IE5 模式显示
<meta name="description" content="不超过150个字符" />页面描述
<meta name="keywords" content="html5, css3, 关键字"/>页面关键词
<meta name="author" content="魔法小栈" />定义网页作者
<meta name="robots" content="index,follow" />定义网页搜索引擎索引方式,robotterms是一组使用英文逗号「,」分割的值,通常有如下几种取值:none,noindex,nofollow,all,index和follow。
<meta name ="viewport" content ="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
content 参数解释:
text-align:justify;
text-align-last:justify;
@plilion
plilion / fontfamily
Last active August 29, 2015 14:12
fontfamily
@font-face {
font-family: 'emotion';
src: url('emotion.eot'); /* IE9*/
src: url('emotion.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('emotion.woff') format('woff'), /* chrome、firefox */
url('emotion.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/
url('emotion.svg#svgFontName') format('svg'); /* iOS 4.1- */
}
@plilion
plilion / hoverdir.js
Created October 23, 2014 02:07
JS判断鼠标从什么方向进入一个容器
var wrap = document.getElementById('wrap');
var hoverDir = function(e){
var w=wrap.offsetWidth;
var h=wrap.offsetHeight;
var x=(e.clientX - wrap.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
var y=(e.clientY - wrap.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
var eventType = e.type;
var dirName = new Array('上方','右侧','下方','左侧');
if(e.type == 'mouseover' || e.type == 'mouseenter'){