A Fisheye for the Prototypejs CommunityA Measurement of proximity to determine the magnification of the icon
What is a Fisheye?The idea behind a fisheye control is a strip of icons, being vertical or horizontally laid out that reacts to the user's mouse as it approaches the icon. This control was made popular by Mac OSX "Dock". Why use a FisheyeIt improves usability and reinforces to the user that this is an interactive component which is ready to respond to the user's action. How do I use this Fisheye?While there are plenty of implementations of this control, which I will link to at the bottom of the article. I believe this approach leaves less stress for the implementor than most. It of course uses prototype and harnesses the DOM Extension methods to enhance performance and reliability across the browser board. It also uses an event style architecture to allow for convienence of attaching methods to a particular item being clicked etc. How can I extend this Fisheye?As noted previously the component is built using prototypejs, the class structure allows itself to be extended very easily through techniques of inheritance. I've also attempted to insert a few hooks to make extension even easier, this is very similar to Thomas Fuchs' implementation of Effects and his options argument to allow for a form of composition. ImplementationThe component only effects three attributes, height, width and marginTop. Height and width im sure you expected but why bother with marginTop? Because if that isn't calculated in the scaling, as one grows to max height it will push all other icons in the toolbar down which creates a kind of "bouncing" effect, trust me it isn't pretty. An HTML MicroformatThe FishEyeToolBar class is expecting a specific microformat to work with, starting from the container, is expecting a list of img tags that will act as the icon to be scaled. You can modify this expectation to any CSS selector that descends from the root element by customizing the selector property in the options argument. The Sword of CSSSo we've got HTML and Javascript at work here, but CSS has a pretty big role in implementing a smooth fisheye. The first big tip is to make sure you're FishEye element has the property text-align:center; this will make sure as the images scale that they stay centered! In my first attempts i was trying to calculate this myself, talk about a headache. Next is a proper marginTop As noted above you can get some horrid looking bouncing effect if this isn't set right, my rule of thumb is set the marginTop to be at least the height of the image that way as the image comes up to double its original height, it will have some margin to eat up before it starts to push the others down. FishEyeToolBarThe FishEyeToolBar class acts as the super class, it listens to the mouseMove event on the containing object and collects the img elements to be constructed into FishEyeItem objects. FishEyeToolBar options
{
selector : "img", // the selector that FishEyeToolBar uses to collect its icons.
createSub : this.createSub.bind(this), //Allows for a custom factory function to create the FishEyeItem object, or whatever you extend from it.
subOptions : {} // for convienence allows you to send options argument to the default createSub method.
};
FishEyeItemThe FishEyeItem class acts as a wrapper class for an img element. It provides easier, encapsulated logic to allow for less work by the FishEyeToolBar class. FishEyeItem options
{
scaleThrottle : 200
}
The scale throttle is pretty simple, it basically acts as the judge for saying is this mouseMovement within my range? If so it will calculate a value between 1 and 2 as a percentage to increase the icon by, the larger the throttle the bigger the effected proximity will be but this will in turn make for a slower, potentially smoother animation, this is something you'll have to mess with to truely perceive. EventDispatcherIn order for the class objects to communicate with other objects they have inherited from the EventDispatcher class. This class was my attempt at custom events, but in the end just turned into a great class for implementing an observer pattern. DemoLooking for a working example? Inspired by the many comments below I have developed a page purely for the purpose of providing a demo. In further development I've also created a subclass to handle the behavior of a fisheye resting on the upper edge of a page that would need to expand down instead of up, check out the demo and you'll see what I mean. Conclusion
Download prototype FishEye Related Links |
||
CommentsAugust 28, 2007francois i am from france, but i still like it August 29, 2007jamie if you click on an icon can it link to something? like an image? September 03, 2007carlos can you show an easier way to implement it September 03, 2007sascha seems not to work with prototype 1.6.x due to event-issues. September 06, 2007cnu.net.cn i am from china ,and i like it very much! September 10, 2007stecher where are the examples ? September 12, 2007samuel lebeau it rocks :) September 25, 2007levent help anyone could say how i can use it ?? September 29, 2007Mitro Does anyone know of a site that gives a step by step guide to getting this to work? October 24, 2007dan it doesnt work :-( October 29, 2007Snarp How can people say it doesn't work, when you can view the code on the page for an example? November 03, 2007asxs s November 09, 2007yeah FUCK YEAH November 12, 2007ee eeeeeeeeeeee November 12, 2007ee eeeeeeeeeeee November 15, 2007jeremy I've made a few changes to the code to get some things working. Mainly the options = {} weren't getting applied and I added a couple items to make it more custom, like resetTime if mouse goes out, made sure scale works and scaleThrottle (affects neighbors). Also removed the click handlers since I'm doing that through hrefs January 10, 2008Thomas K. Nielsen Nice little FishEye tool. Thanks for providing it. January 14, 2008Kelly I've noticed that the icons don't always show up on first load - but then after a refresh it works fine. This is on two PCs, with IE 7 and FF2. Anyone else run into this problem? February 05, 2008Matt Hey Kelly, I believe this problem was due to the height not being explicitly set. When the object went to reset itself, the "originalHeight" was 0 and thus minimized the object beyond visible porportions. February 29, 2008a Let's try it March 04, 2008San4OZE Nice March 06, 2008terrasse Works great ! Thanks a lot. March 22, 2008Sohbet Thanks for this. I did it. March 22, 2008Autocad Thanks a lot. April 20, 2008none thanks ... April 22, 2008MikeW Hi, great Script ! April 26, 2008richai download May 01, 2008abc ojdsojfl;msa June 19, 2008andres This control allow define a caption over the img element?? like a text June 30, 2008Horoscope Yes download ! July 04, 2008Megalith Just what i'm looking for, i already have prototype on this site i'm working on July 18, 2008Tim which height needs to be set to fix this problem (I've noticed that the icons don't always show up on first load) July 21, 2008ilahiler Just what i'm looking for, i already have prototype on this site i'm working on |
||
its cool