Steamed Design

  • Random
  • Archive
  • RSS
  • Ask me anything

Easter eggs jQuery plugin

I decided that a project I was working in needed more monsters so I created a quick jQuery plugin to add them, have fun.

//Change image
//<div data-swapcss-value='url("imageurl.png")'>

//Full options
//<div data-swapcss-property='background-color' data-swapcss-value='red'  data-swapcss-count="3">
var swapCssConfig = {}
var swapCssConfig.currentCount = 0;
(function ($) {
    $.fn.swapCSS = function (options) {

        var settings = jQuery.extend({
            clickCount: 6,
            property: 'background-image'
        }, options);

        var currentElement = this;

        currentElement.click(function () {
            warningClickCount++;
            if (swapCssConfig.currentCount > (settings.clickCount - 1)) {
                currentElement.css(settings.property, settings.value);
                currentElement.unbind('click');
            }
        });
    };

    $(document).ready(function () {
        $('[data-swapcss-value]').each(function (index) {
            var item = $(this);
            var options = { value: item.attr('data-swapcss-value') };

            if (item.attr('data-swapcss-count') !== undefined)
                options.clickCount = item.attr('data-swapcss-count');   

            if (item.attr('data-swapcss-property') !== undefined)
                options.property = item.attr('data-swapcss-property');

            item.swapCSS(options);
        });
    });

})(jQuery);
    • #javascript
    • #jquery
    • #fun
    • #free
  • 1 year ago
  • 9
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Avatar Thoughts and work form a software developer in his attempts to learn some new stuff.

Pages

  • Example Code
  • Photo's from my Phone
  • Alpine Parrot
  • PSN
  • Careers 2.0
  • Old Blog

Me, Elsewhere

  • Korich on Forrst
  • @korich on Twitter
  • Facebook Profile
  • Linkedin Profile
  • korich on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile
Effector Theme by Pixel Union