By Aquil Akhter
http://www.smashingmagazine.com/2009/03/20/30-beautiful-surreal-and-dark-art-pictures/
Art is a thing that attracts almost every individual. Today we would like to share with you two different but very interesting mediums of art which are called as Surreal and Dark Art. These types of art are quite different from other conventional mediums of art. In these medium, artist conveys his thought and imagination in a very mysterious but somewhat fantastic or I should say in a bizarre style.
I personally like these types of arts as they express the most beautiful and positive aspects of life. Artist has much room in these types of art to motivate your life, to inspire you and to bring happiness and positivity in your life. So, here’s the collection of most momentous and conceptually imaginative surreal and dark art works.
Do have a look at these photos and do not forget to share your comments with us.
Creative Surreal and Dark Art Pieces
Mar 18th in Web Roundups by Danny Outlaw
http://psd.tutsplus.com/articles/web/50-brilliantly-photoshopped-movie-posters/Movie posters are meant to be attention grabbing, captivating, stunning and intriguing. The designers have a large canvas to work from, so their creativity has few limits. Because of this, movie posters can result in some of the smartest graphic design you’ll ever see. Here are 50 brilliantly Photoshopped movie posters for your viewing pleasure.
1. Batman: The Dark Knight

2. Watchmen

3. Taken

4. X-Men 3

5. Push

6. Gladiator

7. Day Watch

8. Sin City

9. Pirates of the Caribbean: Dead Man’s Chest

10. Spider-Man 3

11. Death Proof

12. Planet Terror

13. 300

14. Walk the Line

15. Superman Returns

16. Sweeney Todd: The Demon Barber of Fleet Street

17. Crash

18. Ocean’s 12

19. Terminator: Salvation

20. I Am Legend

21. Star Wars Episode 1

22. War of the Worlds

23. Apocalypto

24. Narnia - Prince Caspian

25. Pan’s Labyrinth

26. Cloverfield

27. American Gangster

28. Transformers

29. Fear and Loathing in Las Vegas

30. A Scanner Darkly

31. Hellboy II

32. V for Vendetta

33. Lord of the Rings: The Fellowship of the Ring

34. Bridge to Terabithia

35. WALL-E

36. Napoleon Dynamite

37. Lord of War

38. Big Fish

39. Zodiac

40. Star Wars Trilogy DVD Poster

41. 3:10 to Yuma

42. No Country for Old Men

43. Jurassic Park 3

44. The Eye

45. Iron Man

46. Dawn of the Dead

47. Halloween

48. Perfume

49. Identity

50. Pathfinder

No Comments »
http://blog.sina.com.cn/s/blog_49b35d540100bqws.html
FD软件是指FlashDevelop,是学习、开发Flash ActionScript 3.0的有力工具,其最大的特点是超强代码提示、方便的快捷键操作、开源代码模板定制、可扩充的插件功能,无不展示了这是一款优秀的辅助软件!
本文紧跟Flash CS4,重新配置FD,挖掘FD的优秀功能,让FD直接支持最新版Flash CS4,为学习研究Flash ActionScript 3.0提供最新帮助!
一、下载FD3.0.0 B9:
这里提供免安装简体中文版,下载后直接解压缩即可。特别注意:不要把FD解压缩到以中文汉字命名的文件夹中!
本免安装简体中文版特点:在官方版本基础上,搜集诸多实用之插件,新增功能如下:
1、可自动套用格式,快捷键:alt+shift+f(可以重新设置);
2、类向导,可直接指定继承、接口等;
3、Flash API,方便查找Flash ActionScript 3.0方法、属性(可以当作Flash动作面板中的脚本导航器使用!);
4、正则表达式;
5、ExportSWC;
6、更换AS3帮助为官方Flash CS4 ActionScript 3.0语言和组件参考,此帮助为简体中文在线帮助(帮助→语言参考→FL CS4)。
下载网址:http://qwm2003.ys168.com/
也可以从官方网站上下载FD3.0.0 B9:
迅雷直接下载:http://www.flashdevelop.org/downloads/releases/FlashDevelop-3.0.0-Beta9.exe
二、下载FLEX SDK 4.0最新版:
官方网页下载:http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
迅雷直接下载:http://flexorg.wip3.adobe.com/flexsdk/4.0.0.4229/flex_sdk_4.0.0.4229.zip(目前推荐)
三、配置FD3.0.0 B9直接支持Flash CS4:
本文以免安装简体中文版为例详细介绍FD的配置。
安装版自行参考;但在安装过程中一定要把没有打上对勾的选项全部选择上,否则会出现部分无法配置或配置无法生效!演示图示(如果看不到动态演示,请点击图片两次,下同):
1、解压缩FD到指定的文件夹:例如D:\Program Files\FlashDevelop;
2、解压缩最新版本flex_sdk_4.0.0.4229到指定的文件夹,这里推荐解压缩后把flex_sdk_4.0.0.4229整个文件夹复制到D:\Program Files\FlashDevelop文件夹中;
3、启动FD,新建一个项目:Project–New Project–AS3 Project,新建一个as3project项目,演示图示:
4、工具–参数设置,依次设置相关插件(Plugins):
AS3Context:此插件只要设置Flex SDK Location项,也就是需要指定Flex SDK到我们刚刚解压缩的flex_sdk_4.0.0.4229文件夹,演示图示:
ASCompletion:此插件设置Path To Flash IDE项,也就是需要指定Flash CS4程序的安装路径,演示图示:
FlashAPI:此插件设置指向Flash CS4的ActionsPanel_3.xml文件路径,当设置完成后,即可与CS4动作面板中的脚本导航器功能类似,演示图示:
设置完成后怎么使用呢?视图–Flash API,调出这个面板,将光标定位到所在插入脚本的地方,双击鼠标即可,由于我们连接是Flash CS4简体中文脚本帮助,所以双击后会出现构造函数相关中文提示信息。
FlashViewer:此插件是关键,主要是设置FD能否直接调试输出信息,演示图示:
至此,FD中主要插件设置完毕。
5、设置FD支持Flash CS4
这步的设置决定了FD能否支持Flash CS4的关键,演示图示:
附:三角形测试代码
No Comments »
In this tutorial I will show you how to create a smoke typography effect playing with some brushes and adjustment layers. It’s a very easy tutorial and you will be able to do the whole process in 5-10 minutes.
Step 1
Open Photoshop and create a new document, I used 1920×1200 pixels. Then apply a gradient, you could fill it with a gradient or apply a Layer Style. I used the layer style, Gradient Overlay. Use Radial for the Style and #07090a - #202b35 for the colors.

Step 2
Add some text in white then go to Filter>Blur>Motion Blur. Use 90º for the Angle, and 40 pixels for the Distance.

Step 3
Now go to Filter>Distort>Wave. use 3 for the Number of Generators, 10 and 346 for the Wavelength, and 5 and 35 for the Amplitude.

Step 4
Go to Filter>Blur>Gaussian Blur. Use 10 pixels for the Radius. Then group the layer and rename the folder’s Blend Mode to Color Dodge. You will get a nice light effect.

Step 5
Create a new layer on top of the others and go to Filter>Render>Clouds, make sure you had black and white for the background and foreground colors, then change the Blend Mode to Color Dodge and go to Layer>Layer Mask>Reveal All. With a very soft brush, 0% hardness and black color, hide some areas of the clouds layer. Use the image below for reference.

Step 6
Create a new Folder on the Layers’ Palette. Change the folder’s Blend Mode to Color Dodge and add a new layer in it. Then use the Smoke Brushes from Qbrushes . Select white for the color and paint over some letters. If you think the brush is not very bright, just click twice.

Step 7
Paint a few more smokes like the image below.

Step 8
Create a new layer beneath the other layers but in front of the Background layer. Fill this layer with black and go to Filter>Texture>Texturizer. Use 100% for the Scaling and 4 for the Relief. For the Texture use Canvas and Light use Top. That will add a nice texture to the image but you will need to change the opacity to 10%.

Step 9
This is a nice new feature in the new Photoshop CS4, actually there’s nothing new just the Adjustments palette, but it’s very useful because you can edit all the image adjustments like Levels, Hue & Saturation, Curves in that palette. However it just adds a Adjustment Layer, that could be done in the previous versions too.
Anyway, on top of the other layers just add the Invert adjustment. You can go to Layer>New Adjustment Layer>Invert. It will be the same. You will get a very nice effect, like burning paper.

Conclusion
One of the best things in Photoshop is the Brushes Engine and all the things we can create with brushes. With so many excellent sites with Brushes like Brusheezy, Tutorial9, QBrushes, DeviantArt, and PSDTUTS we can find practically all sorts of effects and elements ready to be used in our designs. That means we can focus on ideas rather than figure out ways to recreate things. Also we have 2 very different effects with just one adjustment layer, the Invert. Once again, it’s all about playing. I hope you enjoyed this quick tutorial, and let me know if you have any questions.

Click here for full preview of the Dark version and here for the Light version
Download the Photoshop File
Click here to download the Photoshop File used in this tutorial.
No Comments »
http://blogs.adobe.com/kiwi/2006/05/as3_programming_101_for_cc_cod_1.html
In my previous article, I covered ActionScript 3 languange syntax and constructs that may be of interest to C/C++ coders starting out on ActionScript 3. This article covers areas of AS3 that are different from C/C++ in regards to functional issues that may be interesting to people with C/C++ experience. ActionScript 3 is a powerful language with some very nice features. However, as a long time C/C++ coder I found ActionScript lacking things I was used to having.
No control over application message loop
In a standard C/C++ application, your application has full control of the message loop. In Flash/ActionScript, this is not the case. The main application message loop is controlled by the application that is hosting the Flash player. This is either the browser, the stand alone flash player, or some other custom application. Flash is purely event driven. Your Flash application receives callbacks for every type of notification. This includes things like user events, application commands, and network responses. This means that ActionScript cannot block for any reason. If your Flash application blocks in a loop (or just just taking a long time computing something), the entire player and perhaps even the host application will block as well. Flash must handle everything via asynchronous callbacks.
In a typical desktop application written in C/C++, modal dialogs manage the message loop. This allows a modal dialog function to block and then return when the user is finished without causing the entire application to freeze. This is not the case in ActionScript. In ActionScript, you must display the modal dialog then return and wait for a callback that indicates what the user chose. This also means that using “alert” dialogs in ActionScript for debugging purposes is not entirely useful since the alert will display and the application will continue running.
Sho Kuwamoto from the Flex Builder team has a running series of articles covering the issues of “Dealing with asynchronous events”. So far, he has Part 1, Part 2, and Part 3 available. I strongly recommend reading these articles. They provide a lot of good information for dealing with asynchronous nature of AS3.
No threads
In Flash/Flex, your application executes in a single thread. If you are used to using threads in your applications, this can feel somewhat constraining. However, since all AS3 applications are event driven and must handle everything asynchronously, AS3 has some nice language features that allows you to make asynchronous calls. Granted, asynchronous function calls are no where near a replacement for true threading, but asynchronous calls can provide for a similar user experience if you architect your application with this design pattern in mind.
The Timer class is very useful in this area. The Timer class allows you to schedule a function to be called by the framework at a later time on fixed intervals via “timer” event notifications. You can think of these timer events as time slices in which your asynchronous logic can execute. Since all Flash applications run in a single thread, you never need to worry about locking, mutexes, or semaphores, but you do need to be careful that any asynchronous function call does not take too long or the application will appear to hang or freeze.
No enum
AS3 has no enum. This can make porting C/C++ code to ActionScript a little more work. The lack of an enum may also disrupt how someone versed in C/C++ would approach a problem. Some people have come up with dynamic runtime solutions. For example, Darron Schall’s EnumeratedType class provides a single class that allows you to declare a new “enum” where ever needed. This is a nice, simple design that solves the runtime issues related to enums. It however does not catch errors at compile time (mismatched assignments or comparisons, etc.), because the AS3 language only has primative types for us to use which can accept any assignment.
Another approach could be as simple as defining a class with statics:
public class MyEnum
{
static public const FIRST:MyEnum = new MyEnum();
static public const SECOND:MyEnum = new MyEnum();
static public const THIRD:MyEnum = new MyEnum();
}
This class then could be used similar to enum definitions when assigning or comparing variables as such:
public function getValue() : MyEnum
{
return MyEnum.SECOND;
}
This way requires you to create a new file/class for each enum, but it enforces type safety because you are passing the data around as a custom type.
Public class constructors and singleton objects
In AS3, all class constructors must be public. This limitation is mainly due to the fact that ECMAscript 4 is not final and AS3 has chosen to abstain from protected/private constructors until it is resolved. But this limitation means is that AS3 does not have a straight forward way of implementing singleton classes. If the constructor must be public, anyone can create an instance of your class. However, there is a little trick you can use to implement a singleton class in AS3 that will ensure that is one and only one instance of your class.
In my previous AS3/C++ article, the section “Only one packaged class per file” touched on an interesting nuance of AS3 that allows you to declare a class outside the package declaration. This class is only accessable to code within that file. We can use this to create an implementation of a singleton class. The following code represents the contents of a file named “Singleton.as”:
package my.package
{
public class Singleton
{
public function Singleton(blocker:SingletonBlocker)
{
if (blocker == null)
throw new Error("Public construction not allowed. Use getInstance()");
}
public static function getInstance() : Singleton
{
return instance;
}
private var instance:Singleton = new Singleton(new SingletonBlocker());
}
}
// Outside the package, declare the blocker class
class SingletonBlocker
{
}
Since the “SingletonBlocker” class is outside the package declaration, other classes do not have access to it. The public constructor of the Singleton class requires the “blocker” parameter, otherwise it throws an exception. The combination of these two controls prevents any code from outside this file from ever constructing a new “Singleton” object instance. The only way to obtain a valid instance is to call the static function “getInstance()“.
No Comments »
http://blogs.adobe.com/kiwi/2006/05/as3_language_101_for_cc_coders.html
This article covers aspects of ActionScript 3 that would be helpful to C/C++ application engineers transitioning to application development in Flex and Flash.
I’ve used C/C++ through most of my educational and professional career. I’ve also done a respectable share of Javascript and Perl. ActionScript 3 could be viewed as an interesting blend of features from all of these languages. Actionscript 3 conforms to the ECMAscript 4 spec. So, it is a standard languange. In addition to the standard language syntax, AS3 contains a custom class framework for working with Flex/Flash.
The following are areas in the AS3 language that I personally found interesting.
Compared to C/C++, the first syntax oddity that you’ll notice is how AS3 declares it’s variable types. All type declarations are in post-fix notation. For example, in C you would define a function like:
int myFunction(char *str);
In AS3 this same function declaration looks like:
function myFunction(str:String) : int
Typecasting
In AS3, think of typecasting like calling the constructor of the type. Functionally, this isn’t what happens, but the syntax is what it appears to be doing.
In C: int i = (int)somefloat;In AS3: var i:int = int(somefloat);
If you see what appears to be something calling the constructor of a class or type but it does not use “new”, it’s not calling a constructor. It’s performing a typecast. For example:
var foo:SomeClass = SomeClass(someObject);
var bar:SomeClass = new SomeClass(someObject);
The first line is typecasting “someObject” into SomeClass. The second line is creating a new SomeClass object, passing “someObject” as a parameter to the constructor. This subtle difference can have wide ranging effects (new object vs. reusing an existing object, etc.). Depending on what the class constructor takes as a parameter, it is possible that both the typecast and the constructor would compile with no errors/warnings in all situations. So, be careful. The difference between a typecast and a new object is just the “new” keyword.
Variable scope
Variables are scoped to the function. ActionScript employs a system called “variable hoisting”, which implicitly pulls all variable declarations in the function (even ones in nested blocks) to the top of the function at compile time. For example:
public function doSomething() : void
{
var foo:int = 4;
if (foo)
{
var bar:int = 2;
}
}
With viable hoisting, all declared variables in a function are moved to the top of the function block at compile time. In the above example, the compile time result looks like:
public function doSomething() : void
{
var foo:int;
var bar:int;
foo = 4;
if (foo)
{
bar = 2;
}
}
Note that the “bar” variable is now in scope for the entire function. This subtle variable handling in AS3 may lead to unintended situations since any use of the “bar” variable before the “if(foo)” block is now valid, even though it is not declared until inside the if() block. AS3 will complain if you declare the same variable more than once in the same function, but it won’t complain if you use a variable before it’s declared.
void *
In AS3, you can use the wild card type to mimic the “void *” type. For example, say you have a factory object that can return objects of many types. This can be implemented as such:
public function wildcard() : void
{
var anything:* = ObjectFactory.getData();
}
Run time type checking
Since you can pass things around as anything using the wildcard type (void *), you need a way to check the type of the object at runtime. To do this, you can use the “is” directive:
public function doSomething() : void
{
var something:* = getData();
if (something is String)
{
// handle string logic
}
else
{
// do something else
}
}
This allows for runtime type checking which allows your application to perform different logic depending on what the given object is.
No function overloading
There is no function overloading in AS3. However, you can implement a system that mimics function overloading. For example, in C++ you might have some function definitions like:
int doSomething(int i); int doSomething(char *str);
In AS3, you can’t overload a function, but the language allows you to make use of the type wildcard “*” and use the “is” directive as a way of performing runtime checks and branching based on what was passed in. For example:
function doSomething(obj:*) : int
{
if (obj is int)
// do int stuff
else if (obj is String)
// do string stuff
else
// what type did you give me?
}
No operator overloading
AS3 has no way to override the meaning of “+”, “=”, or any other operator. The closest functionality is the get/set member accessors that you can declare to handle the getting and assignment of class members.
Everything is an object
All types within AS3 are derived classes of the base class “Object”. Even if a class does not “extend Object”, it still does. This means when you pass anything to a function, you are passing that data by reference (pointer) in all cases. If the called function modifies the object you passed, your version of the data will be modified as well.
However, there are some exceptions. Basic types like int, Number, and String are objects as well, but their implementation performs reference counting to make them behave like stack objects. If the called function simply assigns new values to variables of these basic types, the data in the caller function does not get modified.
Only one packaged class per file
When implementing AS3 classes, you can only have one class definition per package declaration per AS file. For example:
MyClass.as package my.class.package { public class MyClass { public function MyClass() { ... } } }Fig. 1
MyClass.as package my.class.package { public class MyClass { public function MyClass() { ... } } } class MyPrivateClass { public function MyPrivateClass() { ... } }Fig. 2
MyClass.as package my.class.package { public class MyClass { public function MyClass() { ... } } public class AnotherClass { public function AnotherClass { ... } } }Fig. 3
Fig. 1 and 2 are valid in AS3. Fig. 3 is not valid. AS3 does not allow you to have more than one class inside a package declaration and you can only have one package declaration per file. The interesting thing to note is that the “PrivateClass” in Fig. 2 is only accessable to code inside that file. Outside that file, the “PrivateClass” is an unknown type. You can use the construct in Fig. 2 to hide implementation classes from the rest of the world.
Being limited to one public class per file may not be a huge problem, but it may come as a logistical hurdle if you are expecting to define multiple classes within the same file. Plan your file structure accordingly.
virtual functions
The major difference between AS3 and C++ when it comes to inherited functions is the fact that the functions in a derived class do not override the base class functions unless you declare a method as “override“. Without this declaration, the base class version of the function will be called in all cases.
You can think of this as almost the opposite of C++’s “virtual” declaration. In C++, once a function is declared virtual, that function is automatically virtual for all derived classes regardless if the derived class declares it as virtual. In AS3, the derived class controls what functions are “virtual” (overridden).
dynamic_cast
In AS3, you will find yourself dealing with interfaces. These are similar in concept to abstract base classes in C++. Objects that implement an interface will be passed around as instances of that interface. So, given an object of a specific interface, how do you get the object as an instance of its subclass? You use the “as” functionality. For example:
var someInterface:ISomeInterface = factory.getSomeInterface(); var someClass:SomeClass = (someInterface as SomeClass);
If “someInterface” is actually an instance of “SomeClass” or a derived class of “SomeClass”, the variable “someClass” will be a reference to that object. If “someInterface” is an instance of some other class, the “someClass” variable will be null.
Raw character strings
AS3 has a primative string type named “String”. You can access the characters of the string and do things with them, but what if you want access to the raw ASCII or UTF8 bytes? The easiest way to do this is via the ByteArray() class. You can write a string into a ByteArray object and then pull it back out as raw bytes.
Well, I hope this is useful to anyone making the transition to Flex/ActionScript from C/C++. If you have any questions, found an error in my assessment, or just want to say something, please leave a comment. We’re trying to make Flex development as easy as possible for everyone and any feedback is much appreciated.
Thanks!
No Comments »
19
Mar
2009
One Step making an Ajax Tab under jQuery
By derek. Posted in Uncategorized | No Comments »Only one step making an Ajax Tab in the web.
1. Download jQuery UI
“jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.”
Here you can customize your jQuery UI.
2. Include jQuery javascript file in your html
3. Insert an unorded list into html code
<div id=”wrapper”
<ul id=”nav”>
<li><a href=”../AttachmentsByTitle/Tombstone_wall/$FILE/curve_gallery.html”>Recent Deals</a></li>
<li><a href=”../AttachmentsByTitle/Testimonials/$FILE/flash_news.html”>Client Testimonials</a></li>
<li><a href=”../AttachmentsByTitle/Caseinfo_Flash/$FILE/Caseinfo.html”>Case studies</a></li>
<li><a href=”../AttachmentsByTitle/Caseinfo_Flash/$FILE/Case.html”>Project Database</a></li>
</ul>
</div>
4. Write an javascript
$(document).ready(function() {
$(’#wrapper’).tabs({ spinner: ‘Retrieving data…’ });
$(’#nav li a’).click(function(){
window.location.hash = $(this).attr(’href’);
return false;
});
});
5. Done! Test!
6. Advanced animation
No Comments »
http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/
This article contains 10 visual tutorials intended for web designers and newbies on how to apply Javascript effects with jQuery. In case you don’t know about jQuery, it is a “write less, do more” Javascript library. It has many Ajax and Javascript features that allow you to enhance user experience and semantic coding. Since these tutorials are focused on jQuery, I’m not going to get into the details of the CSS.
Note: the version used in this article is jQuery 1.2.3
How jQuery works?
First you need to download a copy of jQuery and insert it in your html page (preferably within the <head> tag). Then you need to write functions to tell jQuery what to do. The diagram below explains the detail how jQuery work:
How to get the element?
Writing jQuery function is relatively easy (thanks to the wonderful documentation). The key point you have to learn is how to get the exact element that you want to apply the effects.
$("#header")= get the element with id=”header”$("h3")= get all <h3> element$("div#content .photo")= get all element with class=”photo” nested in the <div id=”content”>$("ul li")= get all <li> element nested in all <ul>$("ul li:first")= get only the first <li> element of the <ul>
1. Simple slide panel
Let’s start by doing a simple slide panel. You’ve probably seen a lot of this, where you click on a link and a panel slide up/down. (view demo)
When an elment with class=”btn-slide” is clicked, it will slideToggle (up/down) the <div id=”panel”> element and then toggle a CSS class=”active” to the <a class=”btn-slide”> element. The .active class will toggle the background position of the arrow image (by CSS).
$(document).ready(function(){
$(".btn-slide").click(function(){
$("#panel").slideToggle("slow");
$(this).toggleClass("active");
});
});
2. Simple disappearing effect
This sample will show you how to make something disappear when an image button is clicked. (view demo)
When the <img class=”delete”> is clicked, it will find its parent element <div class=”pane”> and animate its opacity=hide with slow speed.
$(document).ready(function(){
$(".pane .delete").click(function(){
$(this).parents(".pane").animate({ opacity: "hide" }, "slow");
});
});
3 Chain-able transition effects
Now let’s see the power of jQuery’s chainability. With just several lines of code, I can make the box fly around with scaling and fading transition. (view demo)
Line 1: when the <a class=”run”> is clicked
Line 2: animate the <div id=”box”> opacity=0.1, left property until it reaches 400px, with speed 1200 (milliseconds)
Line 3: then opacity=0.4, top=160px, height=20, width=20, with speed “slow”
Line 4: then opacity=1, left=0, height=100, width=100, with speed “slow”
Line 5: then opacity=1, left=0, height=100, width=100, with speed “slow”
Line 6: then top=0, with speed “fast”
Line 7: then slideUp (default speed = “normal”)
Line 8: then slideDown, with speed “slow”
Line 9: return false will prevent the browser jump to the link anchor
$(document).ready(function(){
$(".run").click(function(){
$("#box").animate({opacity: "0.1", left: "+=400"}, 1200)
.animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")
.animate({opacity: "1", left: "0", height: "100", width: "100"}, "slow")
.animate({top: "0"}, "fast")
.slideUp()
.slideDown("slow")
return false;
});
});
4a. Accordion #1
Here is a sample of accordion. (view demo)
The first line will add a CSS class “active” to the first <H3> element within the <div class=”accordion”> (the “active” class will shift the background position of the arrow icon). The second line will hide all the <p> element that is not the first within the <div class=”accordion”>.
When the <h3> element is clicked, it will slideToggle the next <p> and slideUp all its siblings, then toggle the class=”active”.
$(document).ready(function(){
$(".accordion h3:first").addClass("active");
$(".accordion p:not(:first)").hide();
$(".accordion h3").click(function(){
$(this).next("p").slideToggle("slow")
.siblings("p:visible").slideUp("slow");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
});
4b. Accordion #2
This example is very similar to accordion#1, but it will let you specify which panel to open as default. (view demo)
In the CSS stylesheet, set .accordion p to display:none. Now suppose you want to open the third panel as default. You can write as $(".accordion2 p").eq(2).show(); (eq = equal). Note that the indexing starts at zero.
$(document).ready(function(){
$(".accordion2 h3").eq(2).addClass("active");
$(".accordion2 p").eq(2).show();
$(".accordion2 h3").click(function(){
$(this).next("p").slideToggle("slow")
.siblings("p:visible").slideUp("slow");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
});
5a. Animated hover effect #1
This example will create a nice animated hover effect with fade in/out. (view demo)
When the menu link is mouseovered, it will find the next <em> and animate its opacity and top position.
$(document).ready(function(){
$(".menu a").hover(function() {
$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");
}, function() {
$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");
});
});
5b. Animated hover effect #2
This example will get the menu linktitle attribute, store it in a variable, and then append to the <em> tag. (view demo)
The first line will append an empty <em> to the menu <a> element.
When the link is mouseovered, it will get thetitle attribute, store it in a variable “hoverText”, and then set the <em> text content with the hoverText’s value.
$(document).ready(function(){
$(".menu2 a").append("<em></em>");
$(".menu2 a").hover(function() {
$(this).find("em").animate({opacity: "show", top: "-75"}, "slow");
var hoverText = $(this).attr("title");
$(this).find("em").text(hoverText);
}, function() {
$(this).find("em").animate({opacity: "hide", top: "-85"}, "fast");
});
});
6. Entire block clickable
This example will show you how to make the entire block element clickable as seen on my Best Web Gallery’s sidebar tabs. (view demo)
Suppose you have a <ul> list with class=”pane-list” and you want to make the nested <li> clickable (entire block). You can assign the click function to “.pane-list li”; and when it is clicked, the function will find the <a> element and redirect the browser location to its href attribute value.
$(document).ready(function(){
$(".pane-list li").click(function(){
window.location=$(this).find("a").attr("href"); return false;
});
});
7. Collapsible panels
Let’s combine the techniques from the previous examples and create a serie of collapsible panels (similar to the Gmail inbox panels). Notice I also used the same technique on Web Designer Wall comment list and Next2Friends message inbox? (view demo)
First line: hide all <div class=”message_body”> after the first one.
Second line: hide all <li> element after the 5th
Third part: when the <p class=”message_head”> is clicked, slideToggle the next <div class=”message_body”>
Fourth part: when the <a class=”collpase_all_message”> button is clicked, slideUp all <div class=”message_body”>
Fifth part: when the <a class=”show_all_message”> is clicked, hide this, show <a class=”show_recent_only”>, and slideDown all <li> after the fifth one.
Sixth part: when the <a class=”show_recent_only”> is clicked, hide this, show <a class=”show_all_message”>, and slideUp all <li> after the 5th.
$(document).ready(function(){
//hide message_body after the first one
$(".message_list .message_body:gt(0)").hide();
//hide message li after the 5th
$(".message_list li:gt(4)").hide();
//toggle message_body
$(".message_head").click(function(){
$(this).next(".message_body").slideToggle(500)
return false;
});
//collapse all messages
$(".collpase_all_message").click(function(){
$(".message_body").slideUp(500)
return false;
});
//show all messages
$(".show_all_message").click(function(){
$(this).hide()
$(".show_recent_only").show()
$(".message_list li:gt(4)").slideDown()
return false;
});
//show recent messages only
$(".show_recent_only").click(function(){
$(this).hide()
$(".show_all_message").show()
$(".message_list li:gt(4)").slideUp()
return false;
});
});
8. Imitating the WordPress Comment Backend
I think most of you have probably seen the WordPress Ajax comment management backend. Well, let’s imitate it with jQuery. In order to animate the background color, you need include the Color Animations plugin. (view demo)
First line: will add “alt” class to even <div class=”pane”> (to assign the grey background on every other <div >)
Second part: when <a class=”btn-delete”> is clicked, alert a message, and then animate the backgroundColor and opacity of <div class=”pane”>
Third part: when <a class=”btn-unapprove”> is clicked, first animate the backgroundColor of <div class=”pane”> to yellow, then white, and addClass “spam”
Fourth part: when <a class=”btn-approve”> is clicked, first animate the backgroundColor of <div class=”pane”> to green, then white, and removeClass “spam”
Fifth part: when <a class=”btn-spam”> is clicked, animate the backgroundColor to red and opacity =”hide”
//don't forget to include the Color Animations plugin
//<script type="text/javascript" src="jquery.color.js"></script>
$(document).ready(function(){
$(".pane:even").addClass("alt");
$(".pane .btn-delete").click(function(){
alert("This comment will be deleted!");
$(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
return false;
});
$(".pane .btn-unapprove").click(function(){
$(this).parents(".pane").animate({ backgroundColor: "#fff568" }, "fast")
.animate({ backgroundColor: "#ffffff" }, "slow")
.addClass("spam")
return false;
});
$(".pane .btn-approve").click(function(){
$(this).parents(".pane").animate({ backgroundColor: "#dafda5" }, "fast")
.animate({ backgroundColor: "#ffffff" }, "slow")
.removeClass("spam")
return false;
});
$(".pane .btn-spam").click(function(){
$(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
return false;
});
});
9. Image replacement gallery
Suppose you have a portfolio where you want to showcase multi images without jumping to another page, you can load the JPG into the target element. (view demo)
First append an empty <em> to H2.
When a link within the <p class=thumbs> is clicked:
- store its href attribute into a variable “largePath”
- store its title attribute into a variable “largeAlt”
- replace the <img id=”largeImg”> scr attribute with the variable “largePath” and replace the alt attribute with the variable “largeAlt”
- Set the em content (within the h2) with the variable largeAlt (plus the brackets)
$(document).ready(function(){
$("h2").append('<em></em>')
$(".thumbs a").click(function(){
var largePath = $(this).attr("href");
var largeAlt = $(this).attr("title");
$("#largeImg").attr({ src: largePath, alt: largeAlt });
$("h2 em").html(" (" + largeAlt + ")"); return false;
});
});
10. Styling different link types
With most modern browsers, styling the link selector is very easy. For example, to style the link to .pdf file, you can simply use the following CSS rule: a[href $='.pdf'] { … }. Unfortunately, IE 6 doesn’t support this (this is another reason why we hate IE!). To get around this, you can do it with jQuery. (view demo)
The first three lines should be very straight foward. They just a CSS class to the <a> element according to their href attribute.
The second part will get all <a> element that does not have “http://www.webdesignerwall.com” and/or does not start with “#” in the href attribute, then addClass “external” and set target= “_blank”.
$(document).ready(function(){
$("a[@href$=pdf]").addClass("pdf");
$("a[@href$=zip]").addClass("zip");
$("a[@href$=psd]").addClass("psd");
$("a:not([@href*=http://www.webdesignerwall.com])").not("[href^=#]")
.addClass("external")
.attr({ target: "_blank" });
});
No Comments »
May 25th in Javascript & AJAX by James Padolsey
In this tutorial we will be taking your average everyday website and enhancing it with jQuery. We will be adding ajax functionality so that the content loads into the relevant container instead of the user having to navigate to another page. We will also be integrating some awesome animation effects.
So first of all, I have put together a very simple layout for this example. Here’s a screenshot and the HTML code we’ll use.
- <!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
- <html xmlns=“http://www.w3.org/1999/xhtml”>
- <head>
- <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8″ />
- <title>mmm… Ajax!</title>
- <script type=“text/javascript” src=“jquery.js”></script>
- <style type=“text/css”>
- @import url(css.css);
- </style>
- <script type=“text/javascript” src=“js.js”></script>
- </head>
- <body>
- <div id=“wrapper”>
- <h1>ajax … nettuts</h1>
- <ul id=“nav”>
- <li><a href=“index.html”>welcome</a></li>
- <li><a href=“about.html”>about</a></li>
- <li><a href=“portfolio.html”>portfolio</a></li>
- <li><a href=“contact.html”>contact</a></li>
- <li><a href=“terms.html”>terms</a></li>
- </ul>
- <div id=“content”>
- <h2>Welcome!</h2>
- <p>Text</p>
- </div>
- <div id=“foot”>Tutorial by James for NETTUTS</div>
- </div>
- </body>
- </html>
Step 1
First thing’s first, go and download the latest stable release of jQuery and link to it in your document:
- <script type=“text/javascript” src=“jQuery.js”></script>
<script type="text/javascript" src="jQuery.js"></script>
One of the best things, in my opinion, about jQuery is it’s simplicity. We can achieve the functionality described above coupled with stunning effects in only a few lines of code.
First let’s load the jQuery library and initiate a function when the document is ready (when the DOM is loaded).
- $(document).ready(function() {
- // Stuff here
- });
Step 2
So what we want to do is make it so that when a user clicks on a link within the navigation menu on our page the browser does not navigate to the corresponding page, but instead loads the content of that page within the current page.
We want to target the links within the navigation menu and run a function when they are clicked:
- $(‘#nav li a’).click(function(){
- // function here
- });
Let’s summarize what we want this function to do in event order:
- Remove current page content.
- Get new page content and append to content DIV.
We need to define what page to get the data from when a link is clicked on. All we have to do here is obtain the ‘href’ attribute of the clicked link and define that as the page to call the data from, plus we need to define whereabouts on the requested page to pull the data from - i.e. We don’t want to pull ALL the data, just the data within the ‘content’ div, so:
- var toLoad = $(this).attr(‘href’)+‘ #content’;
var toLoad = $(this).attr('href')+' #content';
To illustrate what the above code does let’s imagine the user clicks on the ‘about’ link which links to ‘about.html’ - in this situation this variable would be: ‘about.html #content’ - this is the variable which we’ll request in the ajax call. First though, we need to create a nice effect for the current page content. Instead of making it just disappear we’re going to use jQuery’s ‘hide’ function like this:
- $(‘#content’).hide(‘fast’,loadContent);
$('#content').hide('fast',loadContent);
The above function ‘hides’ the #content div at a fast rate, and once that effect finished it then initiates the “loadContent” function (load the new content [via ajax]) - a function which we will define later (in step 4).
Step 3
Once the old content disappears with an awesome effect, we don’t want to just leave the user wondering before the new content arrives (especially if they have a slow internet connection) so we’ll create a little “loading” graphic so they know something is happening in the background:
- $(‘#wrapper’).append(‘<span id=”load”>LOADING…</span>’);
- $(‘#load’).fadeIn(‘normal’);
Here is the CSS applied to the newly created #load div:
- #load {
- display: none;
- position: absolute;
- rightright: 10px;
- top: 10px;
- background: url(images/ajax-loader.gif);
- width: 43px;
- height: 11px;
- text-indent: -9999em;
- }
So, by default this ‘load’ span is set to display:none, but when the fadeIn function is initiated (in the code above) it will fade in to the top right hand corner of the site and show our animated GIF until it is faded out again.
Step 4
So far, when a user clicks on one of the links the following will happen:
- The current content disappears with a cool effect
- A loading message appears
Now, let’s write that loadContent function which we called earlier:
- function loadContent() {
- $(‘#content’).load(toLoad,”,showNewContent)
- }
The loadContent function calls the requested page, then, once that is done, calls the ’showNewContent’ function:
- function showNewContent() {
- $(‘#content’).show(‘normal’,hideLoader);
- }
This showNewContent function uses jQuery’s show function (which is actually a very boring name for a very cool effect) to make the new (requested) content appear within the ‘#content’ div. Once it has called the content it initiates the ‘hideLoader’ function:
- function hideLoader() {
- $(‘#load’).fadeOut(‘normal’);
- }
We have to remember to “return false” at the end of our click function - this is so the browser does not navigate to the page
It should work perfectly now. You can see an example of it here: [LINK]
Here is the code so far:
- $(document).ready(function() {
- $(‘#nav li a’).click(function(){
- var toLoad = $(this).attr(‘href’)+‘ #content’;
- $(‘#content’).hide(‘fast’,loadContent);
- $(‘#load’).remove();
- $(‘#wrapper’).append(‘<span id=”load”>LOADING…</span>’);
- $(‘#load’).fadeIn(‘normal’);
- function loadContent() {
- $(‘#content’).load(toLoad,”,showNewContent())
- }
- function showNewContent() {
- $(‘#content’).show(‘normal’,hideLoader());
- }
- function hideLoader() {
- $(‘#load’).fadeOut(‘normal’);
- }
- return false;
- });
- });
Step 5
You could stop there but if you’re concerned about usability (which you should be) it’s important to do a little more work. The problem with our current solution is that it neglects the URL. What if a user wanted to link to one of the ‘pages’? - There is no way for them to do it because the URL is always the same.
So, a better way to do this would be to use the ‘hash’ value in the URL to indicate what the user is viewing. So if the user is viewing the ‘about’ content then the URL could be: ‘www.website.com/#about’. We only need to add one line of code to the ‘click’ function for the hash to be added to the URL whenever the user clicks on a navigation link:
- window.location.hash = $(this).attr(‘href’).substr(0,$(this).attr(‘href’).length-5);
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
The code above basically changes the URL hash value to the value of the clicked link’s ‘href’ attribute (minus the ‘.html’ extension. So when a user clicks on the ‘home’ link (href=index.html) then the hash value will read ‘#index’.
Also, we want to make it possible for the user to type in the URL and get served the correct page. To do this we check the hash value when the page loads and change the content accordingly:
- var hash = window.location.hash.substr(1);
- var href = $(‘#nav li a’).each(function(){
- var href = $(this).attr(‘href’);
- if(hash==href.substr(0,href.length-5)){
- var toLoad = hash+‘.html #content’;
- $(‘#content’).load(toLoad)
- }
- });
With this included here is all the javascript code required: (plus the jQuery library)
- $(document).ready(function() {
- // Check for hash value in URL
- var hash = window.location.hash.substr(1);
- var href = $(‘#nav li a’).each(function(){
- var href = $(this).attr(‘href’);
- if(hash==href.substr(0,href.length-5)){
- var toLoad = hash+‘.html #content’;
- $(‘#content’).load(toLoad)
- }
- });
- $(‘#nav li a’).click(function(){
- var toLoad = $(this).attr(‘href’)+‘ #content’;
- $(‘#content’).hide(‘fast’,loadContent);
- $(‘#load’).remove();
- $(‘#wrapper’).append(‘<span id=”load”>LOADING…</span>’);
- $(‘#load’).fadeIn(‘normal’);
- window.location.hash = $(this).attr(‘href’).substr(0,$(this).attr(‘href’).length-5);
- function loadContent() {
- $(‘#content’).load(toLoad,”,showNewContent())
- }
- function showNewContent() {
- $(‘#content’).show(‘normal’,hideLoader());
- }
- function hideLoader() {
- $(‘#load’).fadeOut(‘normal’);
- }
- return false;
- });
- });
Finished…
The great thing about this method is that’s it’s adaptable and can be applied to a site within minutes. It’s fully unobtrusive and the website will work normally if the user has JS disabled.
View the Final Working Example
Download the HTML, JS, CSS & Images
No Comments »
Posted by Scott and Maggie on 05/14/2008
- Topics:
- ajax
- jQuery
- ui design
- visual design
1/16/09 Update: we contributed this menu plugin to the jQuery UI library. It’s currently being refactored and slated for release in UI 1.7. You can track its progress at the jQuery UI Planning Wiki (Menu planning page), or better, post feedback or share your own ideas about the jQuery UI planning process by joining the planning wiki.
We created an iPod-style drilldown menu to help users traverse hierarchical data quickly and with control. It’s especially helpful when organizing large data structures that don’t translate well into traditional dropdown or fly-out menus.
This drilldown menu provides easy navigation of complex nested structures with any number of levels. The entire menu sits within a fixed-size area, and when a node is selected, breadcrumb links appear above the menu options to both deliver feedback and allow quick access back to nodes higher up in the hierarchy. A lateral iPod-style slide transition reinforces the notion that you’re moving forward into more granular data, or backward into higher-level data. This menu is specifically useful in traversing deeply nested hierarchies, particularly those more than three levels deep. It also provides a more usable alternative to multi-level fly-out menus, which can present challenges to those with limited manual dexterity.
Working Demos:
The simplest version works like the iPod menu or standard fly-out menu, where the primary goal is to select an end (leaf) node. When you select a category (indicated with an arrow), the menu drills you down into the next level of hierarchy:
View this example in a new window
It’s also possible to configure the menu so that users can select either a category or a leaf node. This is useful for global navigation where users may want to select a higher level category page (Finance) or a detailed page (Mortgage). In this case, the menu options are separated into two parts: a selectable category name (text on the left) and, if applicable, a sub-menu drilldown navigation link (arrow on the right):
View this example in a new window
Development Notes
We built this demo using the principles of Progressive Enhancement. Markup consists of an ordinary HTML link to the menu data, so that when a device can’t handle advanced scripting or has javascript disabled the link is still perfectly usable. As the page loads we run a quick test using our testUserDevice.js script to determine if the user’s device is capable of rendering an enhanced experience. If the device passes our test, we fetch the data from the HREF attribute via Ajax and use it to transform the link into the interactive widget shown above. For more information on testUserDevice.js and Progressive Enhancement, check out Delivering the right experience to the right device.
Code Usage
The iPod-style drilldown menu widget shown here is not coded for ease of modification, but is free to reuse and modify with a proper attribution to Filament Group. Feel free to visit our demo page and view the source code to see how it works.
No Comments »




















































