ars aranea. the web, the way we make it. | |||
27 Sidebar SliderPosted: Dec 3, 2005, under WordPress, DHTML. Updated: Apr 6, 2006. Add a comment!Let me ask you some questions: what use is an empty sidebar? Does the layout of your blog use columns? Do you often find yourself scrolling down a long page and having a column empty for miles and miles? If the answer is yes, this plugin is for you.
1. Plugin overview1.1. BackgroundTogether with JS Toggle Boxes, this plugin is part of my personal vendetta against what I consider to be one of the biggest usability problems with blogs: long, disproportionate columns, which run forever without any practical use. This is actually a well known issue with multi-column layouts, and is even more pressing on blogs. Because of their particularities, almost all blogs need a sidebar. Having the height of the sidebar match the height of the content is a coincidence at best. Most often, one of them runs short at some point during scrolling, and you’re left with empty space for the remainder of the page. 1.2. What it doesThis WordPress plugin makes block elements slide up and down on their respective columns as if they were elevators, while you scroll through the page. This way, visitors can always have the contents of the sidebar, for instance, within easy reach. You’ll never waste screen space again. The plugin uses JavaScript, which is available to some 98% of all visitors, according to statistics. Those that don’t have it activated, won’t miss a thing: they’ll simply get static columns, which they’re already getting now. The plugin uses a smart positioning algorithm. As such, it will follow the visitor’s scrolling in a sensible manner, allowing him to access any part of the page (be it sliding or not) at any time, with minimal effort. 1.3. Plugin demoJust watch the sidebar and the main page content on this blog. Scroll the pages up and down and see how the useful content follows you around efortlessly. 1.4. Distribution termsThis plugin can be freely distributed, modified and used under the terms of the MIT License. 1.5. Additional credits
1.6. ContactLeave a comment or use the contact page. I’m pretty busy so I don’t guarantee a response, but I read all mail and comments. 2. Get the plugin
3. How to use the pluginThe plugin can be used with almost any WP theme. However, it takes a bit of (X)HTML and CSS to know what page elements to hook it up to. For those with the knowledge, it should be pretty easy. I will try to make the instructions very helpful so even beginners can use them, but I can’t possibly cover all possibilities. You have been warned. 3.1. Initialize the pluginFirst, you have to edit your theme and add a call to the
The function takes one parameter, which is optional. If set to false, the JavaScript code is made part of every site page. If set to true, it instructs the plugin to offload the largest part of the JavaScript code at a separate URL, so that browsers can cache it better.
False is the default for the offloading, because there’s less potential for trouble that way.
In order to make an exception for the offloading to work, edit your
3.2. Identifying the (X)HTML elements3.2.1. Finding the sliderHere comes the tricky part: identifying the page element (or elements) that should be sliding, through their
Finding a slider should be easy with a well done theme. Usually, most of them already have a 3.2.2. Finding the containerAlongside the slider, we also need to identify a container element, which will act as sort of a guideline, like the rails for a train, if you want. The slider will use the container’s top edge to know how high it can go, and the container will also serve to guide the slider in its up-down motion.
It may be a bit trickier to find a good container.
3.2.3. Finding a breakerThere is a special case you may run into with some themes. Let’s say you chose the slider and container well. The slider works, goes up and down as needed, and stops well at the top. BUT it doesn’t stop well at the bottom, and overlaps with the footer (the part where you write about copyright and stuff). For such special cases, you must identify the footer as a breaker. This means that the slider will know it should watch out for it and not go lower than it. The overlap effect is thus prevented. Why does this happen? Take the following example, which I’ve seen in some of Becca’s themes:
This case is in obvious need of a breaker. “Wrapper” is the container, while either “content” or “sidebar” (or both) are the sliders. But “wrapper” also envelops “footer”. Therefore the sliding elements will follow it all the way down and overlap the footer at the bottom. So we mark “footer” as a breaker. 3.2.4. Tips and tricksThese are some tips and tricks you can take a look at when all seems lost:
3.2.5. ExamplesI will attempt to add some of the most common case scenarios here, to help those who have trouble locating the elements in their themes. You can also read the comments to add or ask for real world examples.
3.3. Mark the elementsSo, you’ve sweated a lot, but now you’ve identified the
To mark elements, use something like in the following example.
Parameter explanation:
The last 3 parameters are optional and can be omitted from the right. That is, you can omit the breaker and the update interval, but not just the interval.
3.4. Activating the slidersThis is done with a simple call to This is best done towards the very end of your page. Ideally, you should do it very close to the
If you call it from inside a slider, for instance, JavaScript won’t acknowledge its existence, because it’s not “fully defined” yet, as far as it is concerned. So do it right before Here’s the magic code:
3.5. Using the plugin without WordPressIt’s possible to use the slider without having WordPress. Just put the PHP file somewhere on your webserver, The only WordPress-dependent part is the
…with this:
In other words, you replace the use of How to determine what the hardcoded path should be: adjust the following URL in the browser until you manage to see some JavaScript code:
When you suceed, everything between 4. Development informationHere’s how the plugin works, for the benefit of curios developers. 4.1. PHPThe plugin is a wrapper for the JavaScript code. It starts by outputting all the essential JS code as functions, either in the The plugin then builds up an internal array which is populated by calls to Finally, 4.2. JavaScriptThe JavaScript code is where the real fun begins. First of all, some sanity checks are done to ensure that the browser is recent enough and that it offers access to some essential DOM elements. Then, for each slider, we check to see if the slider, container and (if provided) the breaker can indeed be accessed via the provided names. Each of them is then checked to see if they have the proper DOM properties. If any of them doesn’t, that slider is not activated. Once all checks have been done, we can proceed. For each sliders, the update function is called. The function checks the current slider position, in order, against the browser viewport, the container top and bottom edges, and (if provided) against the breaker top edge. After all the checks, the new position is imposed upon the slider using its 4.3. Advanced issuesThere are three important tricks used by this plugin.
4.4. Version history
4.5. To doLearn how to detect the Opera zoom, in order to reset the sliders. Find out why even the block that dictates the page height slides a little when you jump to the end or beginning of the page. Allow visitors to turn sliding on/off, either globally or individually. 5. Known issues5.1. Graceful degradationYour visitors will need JavaScript for this to work. The huge majority have it on. For those that don’t, nothing bad will happen; the layout will simply remain fixed, as if you didn’t have the plugin. 5.2. Cross-browser compatibilityThe JavaScript used by this plugin is not perfect. It cannot be, as long as there are so many browsers out there with so many different implementations. ppk really said it well: “The hell is other browsers.” I tried hard to make it as cross-browser as possible, but I don’t have all the possible browsers at my disposal, and there’s no substitute for actual testing. I read a lot from what other people had to say about the involved tricks and gotcha’s, but I can’t guarantee anything. In particular, I haven’t tested it on Mac and older browsers. I’d appreciate feedback on them. 5.3. Some layouts are not suitableNot all WP themes out there are suitable for this plugin. That’s because some designers use tricks in building the layouts. If, for instance, a layout uses background tricks to integrate the columns with the overall page design, that design will break when the column moves. You’ll know this kind of problem when you see it. ;) 5.4. The Opera zoom featureUsing the zoom in Opera will mess the sliders up. I need more testing to see what’s going on and how this can be fixed. The zoom used by the Web Developer extension for Firefox is NOT affected.
| Important
Categories
Authoring
(1)Books (2)Cross platforms (2)DHTML (12)Graphical design (3)IT today (12)Morals&Politics (10)ODP (1)Random stuff (3)Romania (16)Security (7)SEO (2)Software (8)SQL (1)Standards (7)Technology (3)WordPress (4)[În română] (4)[This website] (2)Time-jump Syndication Need hosting?I've been a happy user of LunarPages since 2005. |
||
Copyright ©2005–2008 Zuavra | |||