Archive for the '技术-ajax' Category


在线主题制作技术实现方案

    在做门户社区实现中,有类似魔秀(http://www.moxiu.com)的在线主题制作需求,这种用户生成内容(UGC)的形式对于活跃社区气氛、提高用户对社区的粘性是大有好处的。

1、技术实现核心问题:

  • 提供用户自助上传图片的工具
  • 根据用户手机的分辨率,提供在线图片编辑工具,让用户选择要裁剪的区域,作为要制作主题的图片的宽和高
  • 用户提交选定的区域范围到服务器,后台程序根据用户选择图片指定的宽和高对图片进行自动裁剪,生成手机主题,当然还可以实现诸如打水印等功能
  • 参考各手机平台主题的制作方法,把背景图片打包成手机主题

2、技术实现方案如下:

  • 用户上传工具,直接使用struts2 的file upload 工具
  • 在线图片选择工具,采用jquery的img area select plugin实现http://odyniec.net/projects/imgareaselect/ 
  • 图片裁剪采用imagemagick实现,可以利用imagemagick的java接口,为灵活起见,避免由于java接口的不完备性及性能问题,使用Runtime.getRuntime().exec来直接调用imagemagick的命令行来完成。

依照此思路,编写了简单的测试代码,测试页面imgareaselect.html 用于演示img area select的使用。

ImagemagickTest.java是使用java 调用imagemagick接口调用实现图片操作的例子。

关于imagemagick其他功能使用的例子(例如打水印等)可以参考http://www.imagemagick.org/Usage/

   以上只是实现了初步的在线对背景图片制作的步骤,后续可以按照各个操作系统的主题制作技术,实现诸如symbian平台主题sis、windows mobile cab的制作。

3、imgareaselect.html

<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>imgAreaSelect examples</title>
  <link rel="stylesheet" type="text/css" href="base.css">
  <link rel="stylesheet" type="text/css" href="imgareaselect.css">
 </head> 

<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="jquery.imgareaselect-0.5.js"></script>
<link rel="stylesheet" type="text/css" href="base.css">
  <!–[if IE 7]>
  <link rel="stylesheet" type="text/css" href="ie_7_hacks.css" />
  <![endif]–>
  <!–[if IE 6]>
  <link rel="stylesheet" type="text/css" href="ie_6_hacks.css" />
  <![endif]–>
<script type="text/javascript">
 function selectionEnd(img, selection)
 {
        //alert(’width: ‘ + selection.width + ‘; height: ‘ + selection.height+’; x2:’+selection.x2);
 } 

 function preview(img, selection)
 {
   var scaleX = 100 / selection.width;
   var scaleY = 100 / selection.height;
   $(‘#duck + div > img’).css({
     width: Math.round(scaleX * 400) + ‘px’,
     height: Math.round(scaleY * 300) + ‘px’,
     marginLeft: ‘-’ + Math.round(scaleX * selection.x1) + ‘px’,
     marginTop: ‘-’ + Math.round(scaleY * selection.y1) + ‘px’
   });
 }
 $(document).ready(function () {
   $(‘<div><img src="duck.jpg" style="position: relative;" /></div>’)
     .css({
       float: ‘left’,
       position: ‘relative’,
       overflow: ‘hidden’,
       width: ‘100px’,
       height: ‘100px’
     })
     .insertAfter($(‘#duck’));
   $(‘#red’).click(function () {
     $(‘#duck’).imgAreaSelect({ selectionColor: ‘red’ });
   });
   $(‘#green’).click(function () {
     $(‘#duck’).imgAreaSelect({ selectionColor: ‘green’ });
   });
   $(‘#blue’).click(function () {
     $(‘#duck’).imgAreaSelect({ selectionColor: ‘blue’ });
   });
 }); 

/*
选择框初始化值大小设定,在社区实现时候选择框的初始化值由程序根据用户手机型号的分辨率来设定初始化值
通过设定最大值和最小值相等,来固定选择框的大小 

*/
 $(window).load(function () {   

   $(‘#duck’).imgAreaSelect({ x1: 120, y1: 90, x2: 280, y2: 210,maxHeight:120,maxWidth:160,minHeight:120,minWidth:160,resizable:false, onSelectChange:preview,onSelectEnd:selectionEnd }); 

 });
</script> 

<body>
<p style="text-align: left;">
<button id="red" type="button" style="color: red;">Red</button>
<button id="green" type="button" style="color: green;">Green</button>
<button id="blue" type="button" style="color: blue;">Blue</button>
</p>
<p style="text-align: center;">
<img id="duck" src="duck.jpg" alt="测试" title="测试"  style="float: left; margin-right: 10px;">
</p>
</body>
</html> 

 

4、ImagemagickTest

import org.apache.log4j.Logger;
import java.io.IOException; 

public class ImagemagickTest {
    private static final Logger logger = Logger.getLogger(ImagemagickTest.class);
    private static final String CONVERT_PROG="C:/ImageMagick-6.3.9-Q16/convert.exe"; 

    /**
     * @param command Description of the Parameter
     * @return Description of the Return Value
     */
    private static boolean exec(String command) {
        Process proc;
        try {
            logger.debug("exec(String):Trying to execute command " + command);
            proc = Runtime.getRuntime().exec(command);
        } catch (IOException e) {
            System.out.println("IOException while trying to execute " + command);
            logger.fatal("exec(String):IOException while trying to execute " + command);
            return false;
        } 

        if (logger.isDebugEnabled()) {
            logger.debug("exec(String):Got process object, waiting to return.");
        } 

        int exitStatus; 

        while (true) {
            try {
                exitStatus = proc.waitFor();
                break;
            } catch (java.lang.InterruptedException e) {
                logger.fatal("exec(String):Interrupted: Ignoring and waiting");
            }
        }
        if (exitStatus != 0) {
                logger.fatal("exec(String):Error executing command: " + exitStatus);
        }
        return (exitStatus == 0);
    } 

    public static void main(String[] args) {
        String cmd=CONVERT_PROG;
        String parameter=" -crop 278×150+99+45 ";
        String inputFile=" D:/imagemagick/bee.jpg ";
        String outputFile=" D:/imagemagick/output1.jpg ";
        exec(cmd+parameter+inputFile+outputFile) ;
    } 

}

FIREFOX / IE Word-Wrap:Word-Break问题

用的是wpzone.netfresh wordpress主题,很烦人的是在Internet Explorer下如果content或sidebar的内容部分一行的内容过长,则经常出现sidebar被挤到页面最下端的情况,而在firefox下没有此种现象。一般出现在如下几种情况:

  • 图片太大超过了width
  • url太长没有正常换行,超过了width
  • 代码太长没有正常换行,超过了width

究其原因是因为对于无空格连续长字符,IE与Firefox将它看成是一个长单词了,因此不会自动换行。

对于IE,可以通过IE专有的CSS属性word-wrap即可实现自动换行:word-wrap:break-word;

对于Firefox,CSS2标准并没有定义类似word-wrap的属性,可以通过overflow属性将撑出的部分隐藏:overflow:hidden

因此为了兼容性,可以使用如下方法:

word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */

修改fresh theme的style.css文件,在#content和#sidebar中增加上述属性以及pre属性

#content {
color:#000;
display:inline;
float:left;
font-size:14px;
line-height:1.5em;
text-align:left;
width:635px;
margin:13px 0 0 20px;
padding:0 0 20px 0px;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}

#sidebar {
display:inline;
background-color:#fff;
float:right;
font-size:12px;
width:230px;
line-height:1.4em;
padding:20px 20px;
margin:15px 20px 15px 0;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
pre {
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

另外对于firefox和opera可以采用javascript方式来避免overflow:hidden的弊端,具体实现可以参考:

Script word-wrap to Firefox - updated version

参考文档:

http://users.tkk.fi/~tkarvine/pre-wrap-css3-mozilla-opera-ie.html

http://elmicoxcodes.blogspot.com/2007/06/script-word-wrap-to-firefox-updated.html

http://jiarry.bokee.com/5871385.html

http://bbs.blueidea.com/thread-2692909-1-1.html

http://www.positioniseverything.net/explorer/expandingboxbug.html

Technorati 标签:,,,,

互联网入口的革命-从ebay desktop 说起

    ebay 的San Dimas project组发布了其desktop的beta版本http://desktop.ebay.com/,基于Adobe的AIR runtime构建,需要AIR Beta 2的支持,因此安装了AIR Beta 1仍然要重新下载安装AIR Beta 2。在功能上ebay desktop beta提供了ebay web站点购物的大部分功能,目前只支持美ebay us,项目承诺在后续一段时间会提供对ebay全球其他站点的支持。

image

1、使用感受:

  • 界面风格:主要以黄色系为主,整体还是比较清爽和大方。
  • 布局上:还是典型的3级导航。第一级为Search框、Home、Find、My Items、Bid/Buy、Feeds导航菜单,对应一级导航下为二级导航。二级导航由于内容较少,导致感觉还是较为空,不是很紧凑。
  • 互动性上:比ebay web更为炫丽和丰富,倒是典型的RIA/AJAX类型程序的风格。但在核心的“搜索”的功能上并没有充分利用RIA平台本身的优势,例如搜索的互动上与一般的搜索没有差异。
  • 内容及功能上:应当是使用ebay web平台的数据库数据,因此数据本身应当与web的内容相同,但在功能上感觉比web还少。另外应当有一部分数据存放到本地,类似于google gears存储离线数据一样(从Google域名的自动转向问题到代理软件)。这样有一个好处,可以对用户正在使用的数据(例如订单内容)在本地离线存储,避免数据的丢失;同时对用户浏览的相关数据、系统需要预先存储的数据等从服务器下载存储到用户本地作为cache以提高浏览速度,策略上可以在用户浏览时候、系统现对闲置时候、用户请求时候。

     值得注意的是一级导航中有Feeds,Feeds的意义何在?可以从两方面分析:用户通过Feed可以订购什么内容,用户的订购行为对ebay有什么用处;<TBC>

     用户通过Feed可以订购什么:用户感兴趣在Watch的Bid/Buy东西的订阅;

     用户的订购行为对ebay有什么用处:通过用户主动的Feed订购行为,简单层面可以更为细致的分析用户的喜好及消费行为,做到更好推荐等个性化服务。

    令人感兴趣的是,ebay的desktop与服务器端交互接口是怎样的呢,怎样保证高性能要求呢?应该是在web接口的基础上进行adaptor,按照RIA要求进行wrapper。

  • 性能上:使用时候CPU占用上相对较大;查询速度还行,网络带宽占用倒是不是很明显,从理论上来说,采用RIA的应用传输的报文应当比web方式的要小一些,毕竟不需要刷新整个页面,只需要传输需要的数据。
  • 稳定性上:存在不稳定现象,中间出现过白屏,预计与AIR平台本身有关系。正如有人评价,MS 的silverlight和Adobe的AIR最后胜出一个最大的悬念就在于谁能够最先解决稳定性和性能上的瓶颈。

总体说来,对于经常使用ebay进行交易的人,还是值得一试的,而且作为一款利用RIA技术实现的客户端来说,其技术意义和代表的“先进生产力”方向还是值得注意的,尽管在各方面尚存在改进的余地。

2、思考

    不管是所谓的web1.0时代、web2.0时代,还是web3.0时代,客户桌面始终是互联网厂商们梦寐以求的资源,这就是所谓的互联网入口之争。

2.1、RIA应用最大的出路应该在于娱乐、商务应用

  • 娱乐应用上:

    基于RIA的音频、视频或电影播放器,支持RIA的浏览器(基于mozilla阵营的xulrunner RIA,基于MS阵营的silverlight),基于RIA的游戏客户端或游戏,基于RIA的IM软件等。

    像google在未来desktop包中推出youtube基于RIA的方案应该是顺其自然的。

  • 商务应用上

    基于RIA的银行客户端、商务协同软件、广告终端等等。   

   目前首先考虑一下电子商务应用方面,像ebay、amazon、paypal这样的电子商务企业拥有自己的RIA客户端有什么好处呢? 提供更为丰富的功能、更好的交互体验,从而以提高用户的粘性。那一天阿里巴巴、淘宝、易趣会开发自己的客户端呢,相信这一天不会太遥远?

2.2、技术上考虑

    在架构搭建上除了要考虑基于典型的B/S模式下基于浏览器的应用开发模式,还需要考虑诸如RIA、mashup这样应用的兴起需求,因此像amazhon在对外接口层面基于SoA的架构还是有重大的意义的,尽管在目前要在整个体系架构中全部采用SoA的框架体系。

    随着Adobe AIR,MS silverlight,Mozilla xulrunner等RIA平台的完善,相信新一代的浏览器会成为天然的RIA平台,因此ajax技术最终会融入RIA平台中,这此过程中,纯粹的服务器的解决方案(例如OpenLaszlo)等尚有一定的空间,但未来服务器端的重点应该还是在对通用RIA通信协议(例如MS、Adobe的)的适配、兼容及应用上。在开发策略上应当尽可能利用已有的成熟协议来进行开发,让大厂商们去推广RIA客户端平台。

    RIA与mashup应用的结合?如果像Facebook的开放平台的战略能够成功,那么会带动一大堆的公司开发其接口,从而带动mashup应用更好的发展,而诸如个人门户等采用RIA+mashup应当就有美好的前途。另外并不是所有的电子商务企业都有能力或兴趣来开发自己的客户端,应该会出现RIA外包性公司,专门为其他互联网厂商外包制作客户端。

3、参考资料

http://ajaxian.com/archives/ebay-desktop-comes-out-of-beta

http://mashable.com/2007/10/01/ebay-adobe-air-desktop-app/

http://xerdoc.com/blog/archives/198.html

 

Technorati 标签: , , , , , , , ,

bubbling-library:YUI Extension for Event-Driven Applications研究

基于YUI 的YUI Bubbling Library最近发布了新版本,YUI Bubbling Library使用了Observer pattern (publish/subscribe pattern)

Observer-pattern-uml

Observer设计模式

1、DOM Event Model

W3C DOM Level2的事件模型规范中,事件在DOM树中的传播过程(从根节点到目标节点)被分为了三个阶段:捕捉(Capture)、冒泡(Bubbling)、目标(Target)。Dom 事件触发后从Root根节点自上而下传播事件到 target 对象(此过程称为 Capture Phase),然后传播事件给 target 对象(此过程称为 Target Phase),最后在自下而上的传播事件(此过程称为 Bubbling Phase)。

eventflow

一些有关DOM Event Model的资料:

  • brainjar.com的The DOM Event Model

http://www.brainjar.com/dhtml/events/

http://www.brainjar.com/dhtml/intro/

  • W3C Document Object Model Events

http://www.w3.org/TR/DOM-Level-2-Events/events.html

  • Opera Event capture explained

http://dev.opera.com/articles/view/event-capture-explained/

  • Mozilla DOM Event Reference

http://www.mozilla.org/docs/dom/domref/dom_event_ref.html

  • Wikipedia DOM Events

http://en.wikipedia.org/wiki/DOM_Events

2、DOM事件模型处理方法

事件模型的处理需要解决两个关键方面:

    • 把一个事件和 HTML 元素绑定起来的方法。
    • 在事件被触发后如何对之进行处理。

在apple开发人员联盟站点上有一篇文档“同时支持三种事件模型“对此讲述得很清晰和全面透彻。

    • 事件绑定的方法

事件绑定是指构造一个响应系统或者用户动作的 HTML 元素的过程。在不同的浏览器版本中,有不少于五种事件绑定技术。

事件绑定方法I:绑定元素属性
<SCRIPT LANGUAGE=“JavaScript”>
function convertToUpper(textbox) {
    textbox.value = textbox.value.toUpperCase();
}
</SCRIPT>
…
<FORM ….>
<INPUT TYPE=“text” NAME=“first_name” onChange=“convertToUpper(this)”>
<INPUT TYPE=“text” NAME=“last_name” onChange=“convertToUpper(this)”>
…
</FORM>
事件绑定方法II:绑定对象属性
document.forms[0].myButton.onclick = myFunc;

使用此种绑定方法,在事件触发的时候,没有办法向事件函数传递参数

事件绑定方法III: 绑定 IE4+<SCRIPT FOR> 标识
事件绑定方法IV:使用 IE5/Windows 的 attachEvent() 方法

attachEvent() 方法的用法如下所示:

elemObject.attachEvent(”eventName“, functionReference);

eventName 参数的值是表示事件名称的字符串,比如 onmousedownfunctionReference 参数是一个不带括号的函数引用,和早些时候描述的事件属性方法中一样。

事件绑定方法V:使用 W3C DOM 的 addEventListener() 方法

addEventListener() 方法的语法如下所示:

nodeReference.addEventListener(”eventType“, listenerReference, captureFlag);

addEventListener() 方法为指定的结点注册了一个事件,表示该结点希望处理相应的事件。这个方法的第一个参数是一个声明事件类型的字符串(不带”on”前缀),比如 clickmousedown,和 keypressaddEventListener() 方法的第二个参数可以和早些时候描述过的函数引用同样对待。第三个参数则是一个 Boolean 值,指明该结点是否以DOM中所谓的捕捉模式来侦听事件。对于一个典型的事件侦听器来说,第三个参数应该为 false(假)

    • 访问事件对象

IE4+ 的事件对象是 window 对象的一个属性,也即需要通过window.event来判断事件类型。这也意味着在所有的实例中只有一个事件对象。

而对于 遵守W3C DOM的浏览器 来说,除了基于标识属性风格的绑定方法之外,其它绑定方法都是把事件对象自动传递给与事件相绑定的函数。传递给函数的是一个单一的参数。开发者需要在函数中定义一个参数变量,来“接收”该参数的值。为了避免和IE中的 window.event 对象互相冲突,请不要把参数命名为 event。举例来说,把它命名为 evt 就相当好。

兼容IE和W3C DOM事件对象引用

function myFunc(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        // process event here
    }
}
能够是被基于IE和W3C DOM事件后,由于DOM存在capture phase、target phase、bubbling phase,
在事件传播过程中涉及许多节点,文档中的每一个结点都可以接收事件,一个典型问题是要区分evt.currentTarget和
evt.target。

W3C DOM结点的事件目标

有两种策略,一个策略是使用 W3C DOM 事件对象的 currentTarget 属性,该属性返回一个处理事件的结点的引用。脚本中的决策树需要考虑这个属性。

function toggleHighlight(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        var elem
        if (evt.target) {
            if (evt.currentTarget && (evt.currentTarget != evt.target)) {
                elem = evt.currentTarget
            } else {
                elem = evt.target
            }
        } else {
            elem = evt.srcElement
        }
        elem.className = (evt.type == "mouseover") ? "highlight" : "normal"
    }
}

另一个可选的方法是考察由 target 属性返回的对象的 ronodeType 属性。一个能够把事件定向给文本结点的浏览器,也可以把一个文本结点的 nodeType 属性值报告为3,而不是报告为元素结点的类型(其值为1)。如果事件的目标是一个文本结点,则脚本程序就可以通过该文本结点的 parentNode 属性来得到其上级元素结点的引用。这种方法的决策树在某种程度上得到更多的改进:

function toggleHighlight(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : "")
    if (evt) {
        var elem
        if (evt.target) {
            elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
        } else {
            elem = evt.srcElement
        }
        elem.className = (evt.type == "mouseover") ? "highlight" : "normal"
    }
}

一个事件处理函数的模板

// shared function
function getTargetElement(evt) {
    var elem
    if (evt.target) {
        elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
    } else {
        elem = evt.srcElement
    }
    return elem

}

function functionName(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : “”)
    if (evt) {
        var elem = getTargetElement(evt)
        if (elem) {
            // process event here
        }
    }
}

其他关于事件模型的一些资料:

    • 同时支持三种事件模型(中英文版本)

http://developer.apple.com/internet/webcontent/eventmodels.html

http://developer.apple.com.cn/internet/webcontent/eventmodels.html

    • Handling events with the DOM – Part I

http://www.devarticles.com/c/a/JavaScript/Handling-events-with-the-DOM-Part-I/

    • Handling events with the DOM - Part III

http://www.devarticles.com/c/a/JavaScript/Handling-events-with-the-DOM-Part-III/

    • DOM Design Tricks II

http://www.alistapart.com/stories/domtricks2/

    • Event handling in the DOM

http://www.javascriptkit.com/dhtmltutors/domevent1.shtml

3、Bubbling Library

Bubbling Library(http://www.bubbling-library.com/)的思想来源于Event-Driven Web Application Design

要使用Bubbling Library的用法,首先还要熟悉YUI Event.

关于Bubbling Library的使用可以其文档及如下资料:

http://yuiblog.com/blog/2007/09/13/bubbling-library-by-caridy/

  • 样例
  • Bubbling Library的适用场合
  • 与jQuery实现机制对比

4、参考资料

Apple中文开发站点的一些文档

http://developer.apple.com.cn/Documentation/InternetWeb/

Pro JavaScript Techniques第六章: 事件

http://bbs.blueidea.com/viewthread.php?tid=2745405&page=1#pid3215727

Learning jQuery

http://www.learningjquery.com/

Yahoo! UI Library: Event Utility

http://developer.yahoo.com/yui/event/

Event Delegation versus Event Handling

http://icant.co.uk/sandbox/eventdelegation/

Unobtrusive Javascript

http://www.onlinetools.org/articles/unobtrusivejavascript/

Technorati 标签: , , , , , ,

CSS Sprites研究

1、What is CSS Sprites

CSS sprites allow you to create a single file that contains all the images laid out in a grid, meaning only a single image and only a single server call, with roughly the same file size because the empty space is compressed. In that file, you will place all individual “sprites” that make up your interface separated by enough space that they don’t start running over each other. You’ll then set the background position (using negative values to move the background up) and include enough space around each sprite so that only it appears in the background of the element, effectively masking the rest of the sprite images

2、CSS Sprites的意义

按照yahoo的 rules for high performance web sites的原则,应当较少Client与Server端间的HTTP Request次数。

通过CSS Sprites方法将多张图片组装成单独的一张图片,可以有效减少HTTP请求的次数。

How To: Minimize HTTP Requests – The Most Important Guideline for Improving Web Site Performance

7 Easy-to-Apply Tips to Improve Your Web Site Performance

Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests

Firebug 及yslow的相关资料

3、CSS Sprites使用

有几篇关于CSS Sprites的文章,基本上把其原理和机制说明得很清楚。

What Are CSS Sprites?

How to create CSS sprites

Creating Rollover Effects with CSS Sprites

Building a Dynamic Banner with CSS Sprites

High Performance Web Sites中关于CSS Sprites的内容3.2. CSS Sprites

4、CSS Sprites的问题

由于IE6存在的background的flicker问题IE6/Win, background image on <a>, cache=‘check every visit’: flicker!,有人针对此问题提出了解决方案Fast Rollovers Without Preload

关于IE6的flicker问题,fivesevensix.com上有一篇很不错的研究文章Minimize Flickering CSS Background Images in IE6

另外:brunildo.orgCSS tests and experiments是关于css各种功能不错的参考手册和测试工具。

5、相关资源

What Are CSS Sprites?

http://www.peachpit.com/articles/printerfriendly.aspx?p=447210&rl=1

CSS Sprites: Image Slicing’s Kiss of Death

http://www.alistapart.com/articles/sprites/

CSS Sprites Generator

http://www.csssprites.com/

http://spritegen.website-performance.org/

Fast Rollovers Without Preload

http://wellstyled.com/css-nopreload-rollovers.html

JavaScript Sprite Animation Using jQuery

http://www.sitepoint.com/blogs/2007/07/20/javascript-sprite-animation-using-jquery/

http://www.sitepoint.com/blogs/2007/07/05/css-using-percentages-in-background-image/

How to create CSS sprites

http://fatagnus.com/how-to-create-css-sprites/

Creating Rollover Effects with CSS Sprites

http://www.devarticles.com/c/a/Web-Style-Sheets/Creating-Rollover-Effects-with-CSS-Sprites/

Building a Dynamic Banner with CSS Sprites

http://www.devarticles.com/c/a/Web-Style-Sheets/Building-a-Dynamic-Banner-with-CSS-Sprites/

CSS Sprites and IE/Win Flicker Issue

http://www.brajeshwar.com/2006/css-sprites-and-iewin-flicker-issue/

css用法测试工具:CSS tests and experiments

http://www.brunildo.org/test/index.html

Technorati 标签: , , , , , , , , ,

jQuery UI 1.0 released (as promised)

jQuery 如期发布了其UI组件框架1.0版本,基于jQuery框架强大的功能(jQuery’s API is deceptively simple, it is consistent across browsers, well documented, it supports many features developers have come to expect of a library, it has a compelling plugin architecture making jQuery extensible in a future-proof manner, and it has an active development cycle and community.),相信jQuery UI应该有很好的前途。

从架构上来看,jQuery UI仍然沿用jQuery的plugin框架机制,这对于保持jQuery架构的稳定性和扩展性是至关重要的,相比较而言,Scriptaculous之于prototype在架构的一致性和延续性上稍显凌乱,从这一层面来说,prototype只能称之为javascript library。

1、jQuery UI的定位:

jQuery UI is a fully themed interaction and widget library built on top of jQuery.

jQuery project which will focus on developing high-quality, reusable, components that you’ll be able to drop in your applications.

2、jQuery UI的一些功能:

Mouse Interaction

  • Draggables - Makes items draggable by the mouse
  • Droppables - Makes drop targets for draggables
  • Sortables - Makes a list of items mouse sortable
  • Selectables - Makes a list of items mouse and keyboard selectable
  • Resizables - Makes an element resizable

User Interface Extensions

  • Accordion - A collapsible content pane
  • Calendar - A dynamic date picker
  • Dialog - Modal floating windows and confirmation dialogs
  • Slider - A sliding input element
  • Table - A sortable table
  • Tabs - A tabbed content pane

Effects

  • Shadow - Generates dynamic drop shadows on any element.
  • Magnifier - Increase and decrease the size of an element, based upon proximity

Other Controls(尚在完善中,参看trunk/plugins/ui

  • Menu,
  • Form Controls
  • Tree
  • Splitter
  • Rich Text Editor
  • Uploader
  • Toolbar
  • Progress
  • Modal
  • Emboss
  • Download
  • 等等

3、例子

可以参看:

http://dev.jquery.com/view/trunk/plugins/ui/apps/gallery/

http://dev.jquery.com/view/trunk/plugins/ui/apps/gallery_advanced/

http://dev.jquery.com/view/trunk/plugins/ui/apps/js_os/

从js_os的初步架构来看,jQuery项目组应该是要基于jQuery搭建一个webos

4、参考文档

http://jquery.com/blog/2007/09/17/jquery-ui-interactions-and-widgets/

http://ui.jquery.com/

http://docs.jquery.com/UI

http://interface.eyecon.ro

Technorati 标签: , , ,

blueprint–css framework研究

1、介绍

blueprint是一个所谓的css framework,相比较而言blueprint 代码中的注释还是比较详细的。

按照Jeff Croft的Frameworks for Designers(或中文版本 理解Web框架,和如何构建一个CSS框架)描述的如何构建一个css framework的方法:

There are several possible ways to go about building a framework, but the most common and arguably the most useful is to abstract your common CSS into individual stylesheets that each cover a particular part of the whole. For example, you may have a stylesheet that sets up the typography and another that handles the mass reset. The beauty of the approach is the ability to selectively include only the styles that you need. You may end up with six or seven different stylesheets in your framework, but if a particular project doesn’t need one or two of them, they don’t have to be included. The framework we created in our office has five stylesheets:.

  • reset.css—handles the mass reset.
  • type.css—handles the typography.
  • grid.css—handles the layout grid.
  • widgets.css—handles widgets like tabs, drop-down menus, and “read more” buttons.
  • base.css—includes all the other stylesheets, so that we only need to call base.css from our (X)HTML documents to use the entire framework.

blueprint的构建方式也与此类似:

分而治之

buleprint在功能组织上,将诸如布局(layout)、排版(typography)、组件(widget)、重置(reset)、打印(print)等功能分散到不同的css文件中。这样方便使用者只需要导入自己所要使用的功能,不用导入全部文件,提高页面装载性能。目前在组件部分只提供了对button的处理,尚未做到麦肯锡的MECE(”相互独立,完全穷尽”)的道。

统一接口:

尽管功能分散到多个css文件,但是导入时候,仍然只需要包含同样的文件screen.css文件,具体的导入细节在screen.css中再处理,统一了对外接口。

<link rel=”stylesheet” href=”css/blueprint/screen.css” type=”text/css” media=”screen, projection” />

blueprint 所包含的css文件说明:

  • screen.css
    This is the main file of the framework. It imports other CSS
    files from the “lib” directory, and should be included on
    every page.

类似于Jeff Croft的base.css功能,只需要包含此文件,就可以导入

  • print.css
    This file sets some default print rules, so that printed versions
    of your site looks better than they usually would. It should be
    included on every page.

用于处理打印,可以归类为widget。

  • lib/grid.css
    This file sets up the grid (it’s true). It has a lot of classes
    you apply to divs to set up any sort of column-based grid.

用于处理页面的布局(栏目)

  • lib/typography.css
    This file sets some default typography. It also has a few
    methods for some really fancy stuff to do with your text.

用于处理页面元素的排版。

  • lib/reset.css
    This file resets CSS values that browsers tend to set for you.

用于重置页面,对没有指定css属性的页面元素指定缺省值。

  • lib/buttons.css
    Provides some great CSS-only buttons.

用于处理按钮,可以归类为widget

  • lib/compressed.css
    A compressed version of the core files. Use this on every live site.
    See screen.css for instructions

提供压缩过的(包含grid.css,tyopgraphy.css,reset.css,buttons.css)的css文件。

2、各模块用法研究

2.1、grid.css研究

  • 对跨浏览器居中处理的兼容性处理

一般而言,要处理firefox、ie在处理居中时候的不同,采用如下方式:

body
{
text-align: center;
}

div#container
{
margin-left: auto;
margin-right: auto;
width: 50em;
text-align: left;
}

摘自:http://www.maxdesign.com.au/presentation/center/

blueprint的处理方式:

body {
  text-align: center; /* IE6 Fix */
  margin:36px 0;
}

/* A container should group all your columns. */
.container {
  text-align: left;
  position: relative;
  padding: 0;
  margin: 0 auto;   /* Centers layout */
  width: 1150px;     /* Total width */
}
  • 分栏(Columns)的实现

blueprint的处理方式:

blueprint定义了.column , .span-x ,.last ,两者结合来实现分栏功能。

其中:.column定义栏目的float属性;.span-x定义栏目宽度;.last将margin-right置为0px,

.column {
  float: left;
  margin-right: 10px;
  padding: 0;
}

/* Use these classes to set how wide a column should be. */
.span-1   { width: 30px; }
.span-2   { width: 70px; }
.span-3   { width: 110px; }
.span-4   { width: 150px; }
…
.span-8   { width: 310px; }
.span-9   { width: 350px; }
.span-10  { width: 390px; }
…
.span-23  { width: 910px; }
.span-24  { width: 950px; margin: 0; }
.span-25  { width: 200px; }
.span-26 { width: 1150px; margin: 0; }
/* The last element in a multi-column block needs this class. */
.last     { margin-right: 0; }

三栏的实现:
<div class=“container”>
        <div class=“column span-24″>
                Header
        </div>
        <div class=“column span-4″>
                Left sidebar
        </div>
        <div class=“column span-16″>
                Main content
        </div>
        <div class=“column span-4 last”>
                Right sidebar
        </div>
</div>
     四栏的实现:
<div class=“container”>
        <div class=“column span-26″>
                Header
        </div>
        <div class=“column span-4″>
                Left sidebar
        </div>
        <div class=“column span-3 “>
                Main content 0
        </div>
          <div class=“column span-25″>
               Main content  1
        </div>
        <div class=“column span-4 last”>
                Right sidebar
        </div>
</div>
注意把.container中的width(定义了整个页面的width)修改为1150px
空白栏目的实现:
   对于多栏目(例如5栏目),其中有空白栏目(例如左右两栏目为空白),可以使用.append-x和.prepend-x来填充。
其中.append-x在栏目后(padding-right)添加空白栏目,.prepend-x在栏目前(padding-left)添加空白栏目。
  • 通用的容器定义
/* A container should group all your columns. */
.container {
  text-align: left;
  position: relative;
  padding: 0;
  margin: 0 auto;   /* Centers layout */
  width: 1150px;     /* Total width */
}

2.2、reset.css研究

reset.css的最初代码应该来自于Eric Meyer,Eric Meyer有两篇关于reset的日志,用于处理跨浏览器缺省值不同的问题。Eric Meyer的文档写得很精彩:

Reset Reasoning:http://meyerweb.com/eric/thoughts/2007/04/18/reset-reasoning/

Reset Reloaded:http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/

  • 为何要reset

The basic reason is that all browsers have presentation defaults, but no browsers have the same defaults. (Okay, no two browser families—most Gecko-based browsers do have the same defaults.)
For example, some browsers indent unordered and ordered lists with left margins, whereas others use left padding. In past years, we tackled these inconsistencies on a case-by-case basis;

  • 为何使用reset style,而不是universal selector

所谓universal selector 就是使用* 来代表document所有的元素,例如

* {
    margin: 0;
    padding 0;
}


  • 关于reset style话题的一些资源:

YUI的reset库:http://developer.yahoo.com/yui/reset/

http://leftjustified.net/journal/2004/10/19/global-ws-reset/

以下几篇实际上是讨论css framework或tips的文章,只不过都提到了reset话题。

http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-coding/

http://www.christianmontoya.com/2007/02/01/css-techniques-i-use-all-the-time/

http://businesslogs.com/design_and_usability/my_5_css_tips.php

http://www.pingmag.jp/2006/05/18/5-steps-to-css-heaven/

2.3、typography.css研究

typography.css用于确定页面元素缺省的排版格式(baseline):

Setting Type on the Web to a Baseline Grid:

http://alistapart.com/articles/settingtypeontheweb

2.4、buttons.css研究

Rediscovering the Button Element 讨论了用button元素来替代input元素的种种好处,button元素是提供了较为丰富的功能。

http://particletree.com/features/rediscovering-the-button-element

2.4、print.css研究

Eric Meyer有一篇关于css实现print功能的文章,可以作为理解print.css的参考。

CSS Design: Going to Print

Print Different

2.5、compressed.css

compressed.css是对blueprint几个文件压缩合成包,同时也对css文件进行了压缩,去除了无用的空格、换行、注释等文本。

此种方式用于在上生产系统部署时候使用,避免在页面导入多个css文件,同时也有利于提高页面性能。

按照lib/screen.css中的说明,应该使用了teenage提供的css压缩服务:

http://teenage.cz/acidofil/tools/cssformat.php

另外类似的提供对css、javascript进行优化、压缩的服务还有:

http://csstidy.sourceforge.net/ (开源)

http://www.cssdrive.com/index.php/main/csscompressor/

http://www.cleancss.com/ (基于csstidy)

3、使用例子

4、参考文档

http://code.google.com/p/blueprintcss/wiki/Tutorial

5、相关项目

blueprint-generator: http://kematzy.com/blueprint-generator/

tripoli : http://monc.se/tripoli/

Technorati 标签: , , , ,

下一页 »