FancyButton
FancyButton is a jQuery plugin to create buttons from a<a> or <input>
FancyButton will wrap the element with a span, prepend it with a span and append it with a span. This way the element remains an inline element and the prepended and appended span can be used to add simple rounded corners / png's while the button will still work normally in IE6. javascript clicks will be put on the container span so the code will be only triggered once, this is very helpful when you work with .net postbacks for example. When the element has a width attribute in the CSS this width will be parsed to the element's code; this will fix the "firebug cannot set the width" bug. Only elements with a class fancybutton will be processed.
A simple example:
This will link to google because we can!
Will show: This will link to google because we can!
Javascript used: [jquery.fancybutton.js] *remove the trailing spans when copyinng
/*
@author: Lucien Immink
@version: 0.6 initial public release
@changelog: 0.6: added hover
*/
jQuery.fn.fancyButton = function(settings) {
// settings
settings = jQuery.extend({
className: 'fancybutton',
hoverClass: 'hover'
}, settings);
jQuery(this).find("."+settings["className"]).each(function() {
// preappend the object with a span, append it with a span
try {
var classes = jQuery(this).removeClass(settings["className"]).attr("class");
if (classes == undefined) {
classes = "";
}
jQuery(this).addClass(settings["className"]);
jQuery("
[in page]
$(document).ready(function() {
$(document).fancyButton();
});
css used:
/* fancyButton */
span.button {
display: inline-block;
overflow: hidden;
}
span.button.green .buttonleft {
background: url(/projects/fancybutton/_left_green.png) no-repeat 0 0;
width: 7px;
display:block;
float:left;
height: 24px;
text-decoration: none;
}
span.button.green .txtbutton {
background: url(/projects/fancybutton/_middle_green.png) repeat-x 0 0;
padding: 2px 5px;
color: #fff;
font-weight: bold;
width: auto;
float:left;
height: 21px;
text-align: center;
text-decoration: none;
}
span.button.green .buttonright {
background: url(/projects/fancybutton/_right_green.png) no-repeat 0 0;
width: 7px;
display:block;
float:left;
height: 24px;
text-decoration: none;
}


July 23rd, 2009 - 21:44
very nice : ))
but i want mouse over button. do you make it?
July 23rd, 2009 - 23:00
the a can have a normal mouse over with the :hover. I can add a class to the surrounding span to get a full mouse over. I’ll publish a new version of fancyButton with this feature* on this page. Other requests are welcome.
* the class can be set in the settings and will default to “hover” the effect of this hover can be registered by CSS ofcouse :)
July 23rd, 2009 - 23:21
Added the 0.6 release which adds a mouseenter/mouseleave event handler to the plugin. This will add a class “hover” when you hover over then container span and removes it when you move your mouse out. The className is overrideable by parsing a different string to the settings.
July 23rd, 2009 - 23:22
Oh on a sidenote: Any modern browser don’t need this release since you control this fully by CSS 2.1
span.button:hover .buttonleft == span.button.left.hover .buttonleft
December 12th, 2009 - 03:11
I really enjoyed reading this post, keep up making such interesting posts.