Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <img src='' class='apple fruit red' />
- $(".apple").mouseover(function() {
- $(".apple").addClass("overState");
- });
- <img src="the-big-red-apple.jpg" class="tagged tag-big tag-red tag-apple" />
- $('img.tagged')
- .each(function() {
- var thisClasses = this.className.split(/s+/); // array of classes.
- var search = [];
- for (var i = 0; i < thisClasses.length; ++i) {
- if (thisClasses[i].substr(0, 4) == "tag-") {
- search.push("." + thisClasses[i]);
- }
- }
- $(this).data("tags", search.join(",")); // ".tag-big,.tag-red,.tag-apple"
- })
- .hover(function() {
- $('img.tagged')
- .filter(this.data('tags'))
- .addClass("highlight")
- ;
- }, function() {
- $('img.tagged')
- .filter(this.data('tags'))
- .removeClass("highlight")
- ;
- })
- ;
- function swapImageGroup(imgSelector,suffix){
- if (suffix == null) {suffix = "-hover";}
- //imgSelector is the jQuery selector to use
- //both imgSelector and suffix must be strings
- $(selector).hover(
- function() {
- $(selector).each(function(){
- //store ".jpg" or ".png" or whatever as fileExtension
- var fileExtension = $(this).attr("src").substr($(this).attr("src").lastIndexOf("."));
- //replace something like ".jpg" with something like "-hover.jpg",
- //assuming suffix == "-hover"
- $(this).attr("src", $(this).attr("src").replace(fileExtension, suffix + fileExtension));
- });
- },
- function() {
- $(selector).each(function(){
- //chop off the end of the filename, starting at "-hover" (or whatever)
- //and put the original extension back on
- $(this).attr("src", $(this).attr("src").split(suffix + ".").join("."));
- });
- }
- );
- }
- swapImageGroup("img.apple");
- swapImageGroup("img.foo","-active");
- a.apple:hover img {
- /* whatever you want to change here */
- }
Add Comment
Please, Sign In to add comment