Ajax Updates |
- Animated Ajax Delete : jQuery
- DatePicker v4 Ajax Script
- JSBIN : Test your Code
- Dynamic Text Effects – MooTools
- Tabbed Content Area : jQuery Plugin
- Pixel Bender Explorer
- How to Mimic the iGoogle Interface
- Auto Playing Jquery Content Slider
- jQuery Slider to control Text Size
Posted: 20 Sep 2009 09:50 PM PDT I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with jQuery javascript.
Demo: http://davidwalsh.name/dw-content/jquery-record-delete.php Source: http://davidwalsh.name/animated-ajax-jquery Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Posted: 20 Sep 2009 01:12 PM PDT My 3rd and final attempt writing a datePicker (calendar) that is accessible using the keyboard, requires no embedded JavaScript blocks, uses no pop-up windows and is suitable for use within documents served as application/xhtml+xml. asked for features into the mix To all & sundry: I've finally managed to devote some time to a complete rewrite of the datePicker/calendar script – again. Full details on the latest version can be found on the Unobtrusive Date-Picker Widget V5 article page. The LowDown My 3rd and final attempt writing a datePicker (calendar) that is accessible using the keyboard, requires no embedded JavaScript blocks, uses no pop-up windows and is suitable for use within documents served as application/xhtml+xml. The more impatient amongst you may want to see the various demos before reading any further. At a glance… * Fully keyboard accessible * Multiple date formats and date dividers supported * Unobtrusive and nameSpace friendly * Fully skinnable with CSS * Both upper and lower date limits can be set * Certain days of the week can be disabled * Certain dates can be disabled/enabled (and wildcards used to stipulate the dates in question) * Includes "smart" localisation * Bespoke days of the week can be highlighted * Works with single text inputs, split text inputs or select lists * It's free to use, even commercially (Released under a CC share-alike license) New features include… * Numerous accessibility enhancements including support for ARIA Roles and States * All keyboard shortcuts now adhere to The DHTML Style Guide Working Group (DSGWG) recommendations * DOM friendly – the calendar is only added to the DOM when actually required * DatePickers can now display an optional status bar and week numbers * DatePickers can now be dragged around the screen (activated by clicking on either the datePicker's header or footer) * Lower and upper date limits can now be set using either a YYYYMMDD date String or a relative "days", "weeks", "months" or "years" notation * The script can parse and format dates using a subset of the PHP strftime conversion specifiers * Global configuration parameters can now be specified using JSON within the script tag itself * The "button" used for popup datePickers can now be styled for default, hover, active and disabled states, be arbitrarily positioned within the DOM and removed from the document tabindex if so desired * Inline datePickers are now available (i.e. no button activation is required), are automatically added to the document's tabIndex and can be arbirarily positioned within the DOM * A bespoke final opacity can be defined for pop-up datePickers and the fade in/out animation effect disabled * The entire grid can now be filled with dates * Bespoke "append id's" can now be set for datePickers split over 3 form elements * The "Today" button can be removed from the U.I. * Three bespoke events, "dateselect", "redraw", and "create" are now available. Demo: http://www.frequency-decoder.com/demo/date-picker-v4/ Download: http://www.frequency-decoder.com/demo/date-picker-v4/date-picker-v4.zip Source: http://www.frequency-decoder.com/2009/02/03/unobtrusive-date-picker-widget-v4 Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Posted: 20 Sep 2009 12:04 PM PDT JS Bin is a webapp specifically designed to help JavaScript and CSS folk test snippets of code, within some context, and debug the code collaboratively. JS Bin allows you to edit and test JavaScript and HTML (reloading the URL also maintains the state of your code – new tabs doesn’t). Once you’re happy you can save, and send the URL to a peer for review or help. They can then make further changes saving anew if required. The original idea spawned from a conversation with another developer in trying to help him debug an Ajax issue. The original aim was to build it using Google’s app engine, but in the end, it was John Resig’s Learning app that inspired me to build the whole solution in JavaScript with liberal dashes of jQuery and a tiny bit of LAMP for the saving process. Javascript:
Demo: http://jsbin.com/ Source: http://jsbin.com/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Dynamic Text Effects – MooTools Posted: 19 Sep 2009 10:32 AM PDT Dynamic text effects (fade ins, moving text, etc.) can enhance the viewer experience by directing attention to specific (and presumably important) areas of the page. All well and good. But how do you do this? Some of the things I like about Mootools are its class-oriented approach, its outstanding plugins and the ease with which you can put together complex effects. But we won't be creating a class here. We're going to keep this real simple… I recently needed to animate some text on a page: specifically, I had to fade in several (distinct) elements in the page header, and produce a fade-in/fly-in effect for some text in the main content area. By itself, this wasn't hard to do but the kicker was that the effect for each element had to fire off in sequence, one after the other. It had to go Snap, Crackle, Pop! What I didn't want was for the effects to fire together because then I'd end up with a snapplepopackle mess. So I turned to the Mootools Chain class for assistance. Let's look at the code behind the demo page; it's short and to the point. Relatively speaking, that is.
Next we iterate over the elements containing the header text in the hdrItems array and do several things: first we set the opacity to 0 so that they're invisible when the page loads; second, we create default instances of Fx.Morph for each element in the array (we'll come back to this in a second); third, we take our default Fx.Morph instances, apply the morph method to generate a transition and load this onto the fnChain call stack. Here's the important thing about getting the Mootools Chain class to do what you want: using the chain and callChain methods is analogous to loading and firing a gun. The analogy works like this: calling the chain method simply loads the gun with bullets, whereas invoking callChain fires a single bullet. Okay, that isn't too hard to grasp … wait, there's something missing. Ah, the finger that pulls the trigger! We kind of need that, don't we? That's where the onComplete event of our Fx.Morph instances comes in: it's the finger that pulls the trigger. And it only pulls the trigger when the last effect has finished. Setting it up this way ensures that all functions loaded onto the fnChain call stack get used. Using the chain and callChain methods by themselves will not get us where we want to be. The last sections of code (with the exception of the last line) basically repeat the process for the text in the content area. The final line:
If you're into Mootools I hope you'll add the Chain class to your toolkit. With it, you can kick up the complexity of your effects by a notch or two. Thanks for reading. Demo: http://richardimanning.com/demos/chaining_demo/chainingDemo.htm Source: http://richardimanning.com/wpblog/2009/02/chaining-functions-in-mootools-for-dynamic-text-effects/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tabbed Content Area : jQuery Plugin Posted: 19 Sep 2009 10:24 AM PDT One of the biggest challenge to web designers is finding ways to place a lot of information on a page without losing usability. Tabbed content is a great way to handle this issue and has been widely used on blogs recently. Today we’re going to build a simple little tabbed information box in HTML, then make it function using some simple Javascript, and then finally we’ll achieve the same thing using the jQuery library. Step 1 First things first, we need something that looks awesome. So a quick trip to Photoshop and voila we have a nice mockup of what our tabbed component should look like. It’s pretty straight forward with a few extra gradients to make it nettuts awesome. You can grab the Photoshop PSD file for this image if you want to take a closer look, but it’s pretty simple and we can build it off the flat JPG really. Step 2The first thing to do when building of course is to get a rough idea how you are going to do it. This gets easier the more things you’ve developed. Looking at this image I would say the best thing to do is:
Don't worry if looking at that image doesn't immediately make you think of that structure. Sometimes you just need to do things by trial and error. In my case I've made these little tabbed things a few times and I know that this is a nice simple way of making them. Also it's nice to think about the structure like this before you have lots of class names and ids and content because it can get hard to see the forest from the trees later on. Especially when you add the content for all the different tabs. So now that we have a picture in mind of how to build our structure, let's get to it! Step 3 Now if you've followed my tutorials on PSDTUTS you'll know that I love a good gradient background. So before we even start with the tabbed structure, let's get ourselves a nice background! Open up Photoshop, create a 1000px x 1000px document and draw a nice (subtle) radial gradient like the one shown below. Note that I've drawn out from the centre/top and made sure that the gradient is finished by the time I get to the edge of the document. That means I can set the background color in HTML to be the darker colour and if someone stretches their browser window it'll be seamless. Step 4 So create a new directory for the project, then create a second directory inside there called images and save that image inside as background.jpg. When saving use File > Save for Web and Devices and select JPG with a quality setting of about 70. That comes out to a file size of 16kb which is not too bad. There used to be a time where you really had to scrimp and save, but now you just want to make sure you're not being stupidly wasteful with your file sizes. Now we create a HTML document and write in some code:
1. It's possible to write this same CSS using shorthand and reduce the number of lines used, but it's much clearer this way and better for tutorial writing! 2. We have a background image (the gradient) and we've set it to no-repeat, because we only want it to appear once, it's centered and finally the background color (#657077) is the darker colour. 3. I've added a margin of 40px. This is just for positioning my stuff later on so that it looks nice. You can see the resulting HTML document here. Note that if you resize your window it's a nice seamless graduated background. Wunderbar! Step 5 Next we add our structure to the page so that we can begin styling it.
1. For the heading, I've placed the subtext "Select a Tab" in a < small > element. This lets me use the < h4 > element for overall positioning and the < small > element to restyle and position the subtext. 2. The container < div > has an id="tabbed_box_1" and a class="tabbed_box". I've done this because we might reuse this code multiple times on the same page. If we did that we could use the id's to position each one in different places. But we'd still have the class to do the styling. Whereas if we'd use the id for styling, we'd end up having to define the same styles again and again for different id's. 3. I've given the links and content areas id's because we need to use Javascript to manipulate them later. 4. Finally I've given the < ul > element a class name. Actually we could style it without a class just by styling .tabbed_area ul { } but this could get confused with future < ul >'s we put inside the content area. So it's better for it to have a class name for us to refer to. OK so without styles it doesn't really look like much.... yet! Step 6 Now with styling up elements, I think it's best to work from the outside element in. So we'll start with this element - - which we'll use to position the box nicely in the center of our document using this code:
Demo: http://nettuts.s3.amazonaws.com/001_Tabbed/site/jQuery.html Source: http://net.tutsplus.com/html-css-techniques/how-to-create-a-slick-tabbed-content-area/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Posted: 19 Sep 2009 09:31 AM PDT Pixel Bender is an exciting new technology by Adobe which brings video and image processing capabilities to the flash runtime. It allows you to create and apply filters to 'bend' pixels and create compelling animations which have never been possible in an HTML environment. Because Adobe AIR uses flash to load any HTML content, we can leverage these powerful filters on a standard Ext Application in the AIR environment. Ext is releasing a Pixel Bender Explorer demo which allows you to explore many of the new filters which have been created by the Adobe Community and demonstrates how to integrate them into an Ext Application. Pixel Bender Explorer Download and install the Pixel Bender Explorer application. Apply different filters or effects by clicking on the Filter Grid. By selecting a filter on the left hand side and adjusting the sliders you can apply live effects to the current target video, browser or image. For some of the filters we have already built some animations such as bend/flatten, waveIn/waveOut, dissolve/combine and tileIn. You can test these animations by choosing the appropriate filter and clicking the animation button above the sliders. These animations can be called within code with a single method call on any Ext.air.NativeWindow or Ext.air.VideoPanel. Here is an example of bending an Ext.air.NativeWindow:
Construction of Pixel Bender Kernels Constructing your own Pixel Bender Effects and Animations is a multi-step process. First, you need to construct a kernel or filter for Pixel Bender. These kernels describe how each pixel should change for a single frame based on a mathematical algorithm which you implement. Kernels are written in the Pixel Bender Kernel Language and compiled with the Pixel Bender Toolkit. The language is very similar to GLSL (OpenGL Shading Language). The benefits of writing effects in this language is that are generalized to all common video hardware platforms and can be used in other Adobe Applications such as After Effects and Photoshop. There is a great article, Pixel Bender basics for Flex and AIR, created by Charles Ward of Adobe that explains the Pixel Bender language in more detail. Using Pixel Bender Kernels After compiling the source code of a Pixel Bender Kernel the extension will change from .pbk (source form) to .pbj (binary/compiled form). The compiled version of the kernel is the only file that we need in order to use the new kernel. After compiling a new kernel, you can place the .pbj file in the kernels/ directory of your installed Pixel Bender Explorer application and you will be able to test it after restarting the application. Pixel Bender Exchange There is a lively community around the creation of Pixel Bender Kernels on the Pixel Bender Exchange, most of which are under an open source license. Download a few kernels and take them for a test run in the Pixel Bender Explorer. The Explorer provides you all of the tools necessary to create your own custom animations for a NativeWindow or VideoPanel. For example, if you wanted to use the smudge filter created by Frank Reitberger as an animation you would determine the paramName that you want to change and where it should start and end along with a few other configurations. Using the same NativeWindow as shown in the example above:
Code Explanation This will tween the value of the parameter amount from 5 to 0 over a duration of 1 second. This will have an effect which I would name smudgeIn because it starts smudged and will eventually look normal. We are using one of Robert Penner's Easing equations easeOutStrong. Support has been added for 15 different easing modes, which explain how fast/slow we adjust the value over time. The filter also needs to be reset at the end of animation because there is no parameter which will not affect the image. (When we set amount to 0 it will still have a slight change on the target.) Anyone who is developing Pixel Bender Kernels, I encourage you to have a parameter which reflects the unapplied state vs the fully applied state. A good example of this are the Adobe filters which use the parameter of transition (0 does nothing, 1 is fully applied). Wrapping up Pixel Bender can spruce up an Ext.air application by adding custom animations to wow your users. However, you should be cautious about the over-use of these filters throughout your application. For a good example of how effective these filters and animations can be to provide proper user feedback you should check Adobe's signature sample BlackBookSafe. Each time an animation occurs it is clear why it happened, not a surprise to the user and adds character to the application. When using these animations you should strive for the same goal, not to surprise your user, but to impress them. Demo: http://www.smart-page.net/smartnormal/fl10.htm Download: http://download.macromedia.com/pub/labs/pixelbender/pixelbender_p7_win_081809.zip Source: http://www.extjs.com/blog/2009/02/19/pixel-bender-explorer/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
How to Mimic the iGoogle Interface Posted: 18 Sep 2009 08:37 AM PDT In this tutorial I’ll be showing you how to create a customizable interface with widgets. The finished product will be a sleek and unobtrusively coded iGoogle-like interface which has a ton of potential applications! The plan First, let’s list exactly what we’ll be creating here and what features it’ll have: * This interface will contain several widgets. * Each widget can be collapsed, removed and edited. * The widgets can be sorted into the three seperate columns by the user (using a drag and drop technique). * The user will be able to edit the color and title of each widget. * Each widget can contain any amount of regular HTML content, text, images, flash etc. Please note that we will only be covering the front-end aspect of the project in this tutorial. Obviously you could integrate this UI with a solid server-side system which could take care of saving preferences and customised widgets. Since it’s all about the user and because the idea was influenced by iGoogle we’re going to be calling this project ‘iNettuts’. The layout of iNettuts The layout is a simple three column one; each column contains widgets: Each widget has a “handle” which the user can use to move the widget around. jQuery UI As well as the jQuery core library we’re also going to make use of the jQuery’s UI library and specifically the “sortable” and “draggable” modules. This will make it quite simple to add the drag-and-drop functionality that we want. You should get a personalized download of the UI library which has what we need in it. (Tick the ’sortable’ box) Step 1: XHTML markup Each column will be an unordered list (UL) and each widget within the columns will be a list item (LI): First column:
Step 2: CSS We'll be using two CSS StyleSheets, one of them will contain all the main styles and the second StyleSheet will only contain styles required by the JavaScript enhancements. The reason we seperate them like this is so that people without JavaScript enabled do not waste their bandwidth downloading styles which they're not going to use.
There's nothing too complicated in the above StyleSheet. Normally it would be better to use images instead of the CSS3 border-radius property to create rounded corners (for cross-browser benefits) but they're not really an integral part of the layout - adding a border-radius is quick and painless. Just a note about the colour classes: Ideally, elements should be named according to their semantic meaning or content, not their appearance. The problem is that the widgets can mean/contain many different things so having classes like this really is the best alternative, unless you're willing to add the colour styles inline. Each colour class is prefixed with 'color-'; it'll become clear why I've done this later in the tutorial. In the above CSS we're also using a min-height hack for each column so that the background images (the dividers) remain intact and so that an empty column can still have widgets dragged back into it:
Step 3: JavaScript Introduction As I've said, we'll be using jQuery. It's the library of choice not only because of the UI modules it offers but also because it will help in speeding up the development process while keeping everything cross-browser operable. The final product will have endless possibilities, some of which have already been explored by the likes of NetVibes and iGoogle. So, we want to make sure our code is easily maintainable, allows for expandability and is reusable; we want it to be future-proof! We'll begin with a global object called "iNettuts" - this will act as the sole occupied namespace of the project (plus dependencies such as jQuery). Under it we will code up the main functionality of the site which utilises jQuery and its UI library.
Settings As I've said, there will be a settings object which will contain all of the global settings required to make this functional. We'll also have individual widget settings objects, this means it will be possible to create per-widget settings. settings object (under iNettuts):
getWidgetSettings object (under iNettuts):
This method will return an object with the settings of any particular widget. If a widget has no id (HTML attribute) then it will just return the default settings, otherwise it will look to see if that widget has settings of its own, if it does then it will return the default settings and that widget's settings merged into a single object (the widget's individual settings have precedence). Attaching a CSS file using JavaScript I mentioned earlier that we have an additional stylesheet which the JavaScript enhancements will require.
The method which attaches this StyleSheet is called 'attachStylesheet':
The next part of the tutorial is probably the hardest, so take it slowly. We want to add another method to our global iNettuts object, we'll call it makeSortable:
This new method will take the settings we specified in the 'settings' object and make the required element sortable. First, we want to make sure everything we need is easily accessible within this new method:
*2: At the very top of the iNettuts object we've placed a new property: 'jQuery : $'. In the pursuit of maximum code reusability we don't want our script to conflict with any other libraries that also make use of the dollar-sign symbol (e.g. The Prototype library). So, for example, if you renamed jQuery to JQLIB then you could change the 'jQuery' property to JQLIB and the script would continue to function properly. The 2nd line in the above code isn't necessary at all, - if we didn't want it we could just use this.jQuery().ajQueryFunction() instead of $() within this method. *3: Again, this isn't really necessary, we're just creating a bit of a shortcut, so instead of having to type out 'this.settings' within this method we only need to type out 'settings'. The next step is to define a set of sortable items (i.e. the widgets that will be movable). Remember, back in the settings we made it possible to set a property called 'movable' to true or false. If 'movable' is set to false, either by default or on individual widgets we have to cater for that:
The mousedown and mouseup functions are needed to work around some issues with dragging and dropping... Since we want this page and all the elements inside it to expand when the browser is resized we haven't set any explicit widths on the widgets (list items). When one of these list items is being sorted it becomes absolutely positioned (while being dragged) which means that it will stretch to its content's composite width. Here's an example: Demo: http://nettuts.s3.amazonaws.com/127_iNETTUTS/demo/index.html Download: http://nettuts.s3.amazonaws.com/127_iNETTUTS/source.zip Source: http://net.tutsplus.com/tutorials/javascript-ajax/inettuts/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Auto Playing Jquery Content Slider Posted: 18 Sep 2009 08:26 AM PDT I love the Coda Slider plugin for jQuery. I've used it recently to build a couple of tabbed "widgets". One here on CSS-Tricks in the sidebar to show Script & Style links, Featured Posts, and Popular Posts. Just kind of a fun way to show lots of content in a small area. I also used it on an article for NETTUTS for a similar purpose. Both of these examples use the Coda Slider pretty much "out of the box". Sure the design was heavily altered to fit the job, but the actual functionality wasn't altered in any way. I recently had the calling to build a "featured content area". The Coda Slider fit the bill almost perfectly, but it needed a little functionality surgery to do what I wanted it to do. Special thanks to Benjamin Sterling for helping me out and figuring out some quirks for me. Like I said, the Coda Slider was 90% there already. There is a main content area (panels, if you will), which slide from left to right each with different unique content. There is generally a set number of panels, but the code is written in such a way that adding or removing panels isn't a huge pain. There are links which act as navigation to quickly jump to any particular panel. These links can be anything (text hyperlink, thumbnail, etc) and link to a unique hash value URL (each panel has a unique URL if need be). Coda Slider provides all of this out of the box. Here is what we need in addition: * Different types of custom content in the panels. We can already put whatever we want in the panels, but to make it easier on ourselves, there will be a couple of different formats ready to go. The main one being an image the size of the entire panel, but featuring a text-overlay. * Auto-play. You can still click the thumbnails to jump to any panel, but left onto itself, the slider will slowly cycle through the panels. * Arrow indicator. To serve as a visual indication of which panel you are currently viewing, a small arrow will display above the thumbnail pointing into the panel. Let's go through the HTML, CSS, and JavaScript. The HTML Here is the framework HTML for just the slider itself:
The CSS The full CSS for this example has a basic reset, some utility styles and basic structure. Below, I'll just show you the CSS relevant to the slider itself, but you can view the full CSS here.
Anything in there that starts with ".strip" is core to the slider itself, getting those panels set up and the wrapper around them, all the CSS magic needed to make a slider do its thing. From ".nav-thumb" on down is stuff specific to this example. The thumbnails have thin black borders. The meta-data section is pushed off the panel by the image, but then is forced back up with a negative top margin and a transparent black background applied. The ".active-thumb" class is very important too, if a thumbnail has this class, it gets the special background applied, which is the white arrow we wanted to indicate the current panel. This class will get applied and removed in the JavaScript. The JavaScript In the header section of your HTML, you'll need to include jQuery and all the plugin files. The bare minimum basics look like this:
Demo: http://css-tricks.com/examples/FeaturedContentSlider/ Download: http://css-tricks.com/examples/FeaturedContentSlider.zip Source: http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/ Related Listings:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jQuery Slider to control Text Size Posted: 18 Sep 2009 07:57 AM PDT JQuery’s UI can add so much to a web page. There are many different widgets that the UI provides. One up and coming star, is the slider. In this tutorial, I will show you how to use a slider to control the text size of an article on a page. This lets the user control exactly the size that suits them, and is also a pretty impressive feature to have on a site! Behavior: * When the slider is dragged, a bubble will fade in, telling the current size. * The text “current text size” will also appear with the current text size next to it. * We will also attempt to make the text increase one px or decrease one px on the click of the plus or minus sign. Step 1: Getting the Necessary Javascript Files Obviously we need JQuery, but we’re also going to need some UI files to extend JQuery. We can get a UI file that is custom to our needs at the JQuery UI Build Your Download page. As you can see, there are some really great sounding effects there! As tempting as it may be though, we don’t need all of these effects to achieve the desired product. All we need is: * UI Core * Slider * Klaus Hartl’s Cookie plugin Step 2: The HTML For this tutorial, I’m not going to waste time explaining the basics of HTML, and creating a layout using it and CSS. If you’d like to learn more about that, there are other tutorials here like my Top Panel tutorial or Collis’ Tabbed Content tutorial.
1. The PNG fix for IE 5.5 and 6. I've linked directly to the google code page. This means I will have to end every transparent PNG with a -trans.png . 2. I have also linked directly to JQuery and our custom made UI file. 3. I have put the necessary tags for the slider in the #header NOTE: For the slider to work, we need to have a bar and a handle. Step 3: The CSS Here is the CSS to make that page look a little bit better. This page is pretty simple, and therefore the CSS is pretty simple as well:
Notice that all of the png images that have alpha transparency have a -trans.png ending. Step 4: Basic Slider Effects When I was first learning about the slider effect, I Googled it to research a little bit more about it and how it works. Well I was lucky to find this amazing screencast. It had a really neat effect too; a caption that appeared to display the position of the slider, on top of the slider. Unfortunately, they stopped there. We're going to use a variation of their JQuery code as a jumping off point:
Some Key Ideas: * First, we hide the caption with Javascript. This makes the caption visible if Javascript is disabled for just a little bit more accessibility. * As you can see, we now have a .slider modifier and several sub items as well: o startValue : This specifies the position that the handle starts at o minValue : This specifies the minimum value that the handle will go to o maxValue: This specifies the maximum value that the handle will go to o start: This allows us to tell JQuery what to do when the user starts sliding the bar o stop: This specifies what happens when the slider is let go of o slide: This specifies what happens when the slider is being slid o handle: This allows us to specify what will be the handle * We also assign a variable that will help us know, when stop: occurs, whether the caption is visible or not, and then perform an action based on that conclusion. * We also had to put a limit on the font sizes possible, so we limited the slider value possibilities to between 8 and 23. We did this by performing basic math on the value of the slider. (multiplied it by 15/100 and added 8 ) * This equation resulted in decimal place sizes, so we had to round it the Math.round * Notice also, the method by which we made the caption stay on top of the handle. We made the css left value of the caption equal to the handle. * Notice that on the stop: I have the text size animated, while on the slide, I have the css size constantly changing. This might seem counter-intuitive, that on slide: I wouldn't animate it, but by the essence of gradually sliding and enlarging the size it does the same thing. If I were to animate instead of just changing the css, it would be choppy and unresponsive. Step 5: Adding the Text Caption
Key Ideas about #font_indicator * We added the same fade in and fade out effects in the same spots as the caption * We left out the css left position though * Notice that we have a tag within the div#font-indicator. This not only makes the number stand out more, but allows us to just put the current slider handle value as text into it. If we just appended to the end of the div, every font size value would just pile up at the end. Step 6: Giving the Plus and Minus Actions This just wouldn't be a functional design, if we didn't give the plus and minus signs actions on click. This code might be a little bit sloppy and not perfectly efficient, but it gets the job done. This project required a surprising amount of math, which explains some of the wacky numbers that end up being used. Without further ado, here is the rest of the javascript, I'll explain it afterward:
* If you know basic Javascript syntax, this should be pretty self evident. * I assign an initial variable to get the current font size. * I then convert it to an integer * I then create another variable that is one value higher. * I place a limit between under 24 and above 8, by using an if else statement. Math Time Adjusting the handle and caption to react to the plus and minus click was a real challenge. What I ended up doing, was figuring out the width of the bar (316px), and dividing that between the 16 possible font sizes (8-23) to figured out how much space each increment took. To be safe, I then needed to figure out the starting spot for the font size. I knew this wasn't exactly 12, because I modified it slightly with the 15/100 + 8. So I took the starting value of the handle (26) and multiplied it by that: 26*15/100 + 8= I figured that, since it was rounded it would be twelve anyway. So I figured that the handle would be the [font size*19.75 - 158 (The first 8 sizes)]px. Just thought that I'd give you a glimpse into my weird and over complicated math .There's probably much easier ways to do it, but I guess this is my logic. Step 7: Cookie Time, reading the cookie For dealing with cookies I used Klaus Hartl's excellent cookie plugin. You can view the basic syntax of the plugin in the link I provided. The challenge, was to find a spot that would reliably set the cookie. I ended up setting it when the browser refreshes or changes the page. This way, it only does it when necessary and realiably too. First we add the code to the top of the javascript file to read the cookie:
* I first read the cookie and sent it to the variable startSize * I then changed that variable into an integer * I then added that number to the default css of the text Step 8: Setting The Cookie As I mentioned above, we need to set the cookie when the page is exited. We do this by using the following code:
* NOTE: This JS is outside of the JQuery $(function() {}); * First, I activated a function when the browser left the page * Then I converted the text size into an integer * Then I put this into the cookie Demo: http://nettuts.s3.amazonaws.com/065_jQueryTextSlider/Text%20Slider%20Demo/index.html Download: http://nettuts.s3.amazonaws.com/065_jQueryTextSlider/Text%20Slider%20Demo.zip Source: http://net.tutsplus.com/tutorials/javascript-ajax/use-the-jquery-ui-to-control-the-size-of-your-text/ Related Listings:
|
You are subscribed to email updates from Ajax Updates To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.