Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created July 9, 2013 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alnutile/5956853 to your computer and use it in GitHub Desktop.
Save alnutile/5956853 to your computer and use it in GitHub Desktop.
Example of plugin to swap out an image to point left or right as the user clicks the "link"
//Example of file using it
$(document).ready(function () {
$('h2').on('click', function(){
var location = window.location.origin;
var url = "/sites/all/themes/chroma-blue/images";
var down = "down.jpg";
var right = "right.jpg";
//Look in plugins.js
$(this).arrow({
location: location,
url: url,
down: down,
right: right
});
});
(function($) {
$.fn.arrow = function(options){
var settings = $.extend({
location: window.location.origin,
url: '/sites/all/themes/chroma-blue/images',
down: 'down.jpg',
right: 'right.jpg'
});
if( $(this).css('background-image') === 'url('+settings.location+settings.url+'/'+settings.down+')' ) {
$(this).css('background-image', 'url("'+settings.url+'/'+settings.right+'")');
} else {
$(this).css('background-image', 'url("'+settings.url+'/'+settings.down+'")');
}
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment