通常我们会检测用户是否是在操作然后来执行一些动作,这个在facebook、gmail等应用程序中用的比较多,主要是通过在固定的周期内监听mousemove和keydown事件来决定用户是否是空闲状态。Nicholas C. Zakas写了一个空闲时间检测的程序,实现了以下功能:允许空闲时间检测开始和结束;当空闲的时候可以触发一个事件;空闲之后当激活后也可以触发一个事件;空闲的时间可控。这里demo
/**
* Idle timer
* @module idle-timer
*/
YUI.add(”idle-timer”, function(Y){
//————————————————————————-
// Private variables
//————————————————————————-
var idle = false, //indicates if the user is idle
tId = -1, //timeout ID
enabled = false, //indicates if the idle timer is enabled
timeout = 30000; //the amount of time (ms) before the user is considered idle
//————————————————————————-
// Private functions
//————————————————————————-
继续阅读 »
function walk(el, tag, walk, start, all){
var el = document.getElementById(el)[start || walk], elements = all?[]:null;
while(el){
if(el.nodeType === 1 && (!tag || el.tagName.toLowerCase() === tag)){
if(!all)return el;
elements.push(el);
}
el = el[walk];
}
return elements;
}
getNext: return function(el, tag){return walk(el, tag, ‘nextSibling’);}
getAllNext: return function(el, tag){return walk(el, tag, ‘nextSibling’, null, true);}
getFirst: return function(el, tag){return walk(el, tag, ”, ‘firstChild’);}
Asvin Balloo开发了一个基于Web的简单图片编辑器pixidou,这里是demo,以及在Github的源码。
对于图片的处理主要是通过一个class.upload.php这个类,而前端则主要是利用了YUI的各个组件,可以说对YUI使用地比较全面。
* reset-fonts.css - for all resetting, style information
* utilities - for all AJAX, animation, drag drop, event handling stuff
* container - for all panels, dialogs, alerts
* menu - for the top navigation menu together with the submenus
* button - provides nice buttons
* slider - for adjusting contrast and brightness
* color picker - to choose the color to tint the image
* resize - to resize the image
* image cropper - image cropping utility
* json - to parse all JSON data returned from PHP scripts
* layout - the general layout
* tabview - for the about information 继续阅读 »
什么是闭包?“官方”的解释是:闭包是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。闭包的两个特点:
1、作为一个函数变量的一个引用 - 当函数返回时,其处于激活状态。
2、一个闭包就是当一个函数返回时,一个没有释放资源的栈区。
例:
<script type=”text/javascript”>
function test(name) {
var t = ‘hello ‘+name;
return function() {
alert(t);
}
}
var a = test(’adam’); a();
</script> 继续阅读 »