This plugin allows you to duplicate the CSS:hover effect, along with some professional jQuery frosting on top. It's as easy as :hover, but lets you do a whole lot more!
Note: To make the plugin work in Opera, you MUST specify height, width, top, and left!
You can name your button element anything you want.
<div class="myButton">
Any text content you want here
</div>
Though you can name your button element whatever you want, you MUST include a span.bg_fade class in the CSS class, as the jquery references this by name. Bold items are required!
.myButton {
position:relative;
height: 75px;
width: 500px;
cursor:pointer;
display:block;
background: url('button.png') no-repeat top left;
}
.myButton span.bg_fade {
position: absolute;
display:none;
top: 0;
left: 0;
height: 75px;
width: 500px;
background:url('button.png') no-repeat 0px -75px;
}
$('.myButton').hover(function(){
$(this).bgFade('fadeIn');
}, function() {
$(this).bgFade('fadeOut');
});
$('.myButton').hover(function(){
top: "",
left: "",
height: "",
width: "",
fadeSpeed: 200,
fadeToOpacity: 0,
animate: false
}, function(){
top: "",
left: "",
height: "",
width: "",
fadeSpeed: 200,
fadeToOpacity: 0,
animate: false
});
top (integer - image location):
left (integer - image location):
height (integer - image size):
width (integer - image size):
fadeSpeed (integer in milliseconds):
fadeToOpacity (number <= 1):
animate (Boolean):
well done
http://www.mightymeta.co.uk/animating-opacity-of-background-image-in-jquery-without-affecting-child-elements/
@Everyone else - Thanks!
Opera
Thanks
I would appreciate any kind of help!
Thanks!!
If you'll notice, the CSS changes the offset of the background image. The hover class for the span element has this as for the background image: background:url('button.png') no-repeat 0px -75px;
That way, you don't have to wait for the hover image to load, because the whole image loads. This link will tell you more about how it works: http://www.switchonthecode.com/tutorials/css-tutorial-the-background-position-property
Thank you for sorting it out!
.myButton {
position:relative;
height: 373px;
width: 250px;
cursor:pointer;
display:block;
background: url("_images/graphic.jpg") no-repeat top left;
}
.myButton span.bg_fade {
position: absolute;
display:none;
top: 0;
left: 0;
height: 373px;
width: 250px;
background:url("_images/graphic.jpg") no-repeat 0px -373px;
}
this html in:
and this code in the header:
$(".myButton").hover(function(){
$(this).bgFade('fadeIn');
}, function() {
$(this).bgFade('fadeOut');
});
any ideas why this isnt working?
Many thanks,
Ryan Mc
Always good to see, this was a brilliant post. In theory I would like to write like this too. You need time to creat that interesting and additionally real effort to make such a good article.