Permalink
Browse files

first plugin version

  • Loading branch information...
kerphi committed Apr 22, 2012
1 parent e277da7 commit 943280f35642af03348a1f6cd48fb6983ed40c88
Showing with 153 additions and 0 deletions.
  1. +43 −0 demo/demo1.html
  2. BIN demo/light.png
  3. +110 −0 jquery-broken-neon.js
View
@@ -0,0 +1,43 @@
+<!doctype html>
+<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
+<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
+<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
+<head>
+ <meta charset="utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+ <title>Demo 1</title>
+ <meta name="viewport" content="width=device-width" />
+ <style>
+ body {
+ background-color: #000;
+ }
+ .light {
+ border: 1px solid grey;
+ display: block;
+ margin: auto;
+ }
+ </style>
+</head>
+<body>
+ <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
+ <header>
+ </header>
+
+ <div role="main">
+ <img src="light.png" alt="neon light" class="light" />
+ </div>
+
+ <footer>
+ </footer>
+
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="../jquery-broken-neon.js"></script>
+ <script type="text/javascript">
+ $('.light').brokenNeon('slow');
+// $('.light2').brokenNeon('fast');
+ </script>
+
+</body>
+</html>
View
Binary file not shown.
View
@@ -0,0 +1,110 @@
+/**
+ * jQuery Broken Neon effect 1.0.0
+ *
+ * Copyright (c) 2012 Stéphane Gully
+ *
+ */
+(function($) {
+
+ $.fn.brokenNeon = function(method) {
+
+ var methods = {
+
+ init : function(options) {
+ this.brokenNeon.settings = $.extend({}, this.brokenNeon.defaults, options);
+ return this.each(function() {
+ var $element = $(this), // reference to the jQuery version of the current DOM element
+ element = this; // reference to the actual DOM element
+
+ //helpers.slow_effect(element);
+ });
+ },
+
+ slow: function () {
+ helpers.slow_effect($(this));
+ },
+ fast: function () {
+ helpers.fast_effect($(this));
+ },
+ }
+
+ var helpers = {
+ slow_effect: function(elt) {
+ var element = $(elt);
+ element.stop()
+ .css('opacity', 1)
+ .css('display', 'block')
+ .wait(Math.random()*1000)
+ .animate({opacity: 0}, 0)
+ .wait(50)
+ .animate({opacity: 1}, 0, function() {
+ setTimeout(function() {
+ helpers.slow_effect(element);
+ }, Math.random()*10000);
+ });
+ },
+
+ fast_effect: function(elt) {
+ var min_opacity = Math.abs(Math.random()-0.5);
+ $(elt).stop()
+ .css('opacity', min_opacity)
+ .css('display', 'block')
+ .wait(Math.random()*100)
+ .animate({opacity: 1}, 0)
+ .wait(100+Math.random()*500)
+ .animate({opacity: min_opacity}, 0, function() {
+ setTimeout(function() {
+ helpers.fast_effect(elt);
+ }, 10);
+ });
+ },
+
+ off_effect: function(elt) {
+ $(elt).stop()
+ .css('opacity', 1)
+ .css('display', 'block')
+ .animate({opacity: 0}, 0).wait(50).animate({opacity: 1}, 0)
+ .animate({opacity: 0.6}, 200)
+ .animate({opacity: 0}, 0).wait(20).animate({opacity: 0.6}, 0)
+ .animate({opacity: 0}, 200);
+ },
+
+ on_effect: function(elt) {
+ $(elt).stop()
+ .css('opacity', 0)
+ .css('display', 'block')
+ .animate({opacity: 0.3}, 200)
+ // .animate({opacity: 0}, 10).animate({opacity: 0.3}, 10)
+ .animate({opacity: 0.6}, 200)
+ .animate({opacity: 0}, 15).animate({opacity: 0.6}, 5)
+ .animate({opacity: 1}, 200);
+ }
+
+ }
+
+ if (methods[method]) {
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
+ } else if (typeof method === 'object' || !method) {
+ return methods.init.apply(this, arguments);
+ } else {
+ $.error( 'Method "' + method + '" does not exist in brokenNeon plugin!');
+ }
+
+ }
+
+ $.fn.wait = function(time, type) {
+ time = time || 1000;
+ type = type || "fx";
+ return this.queue(type, function() {
+ var self = this;
+ setTimeout(function() {
+ $(self).dequeue();
+ }, time);
+ });
+ }
+
+ $.fn.brokenNeon.defaults = {}
+
+ $.fn.brokenNeon.settings = {}
+
+})(jQuery);

0 comments on commit 943280f

Please sign in to comment.