Skip to content

Commit

Permalink
[v1.1] bugfix: initial fade-in works as expected. update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jgv committed Apr 28, 2012
1 parent eeff156 commit cbf8e23
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.lock
85 changes: 85 additions & 0 deletions readme.md
@@ -0,0 +1,85 @@
# okhover by OKFocus

OKHover is a jQuery plugin that makes it easy to reproduce the tiled background effect seen on the [OKFocus website](http://okfoc.us "OKFocus"). It uses HTML5 data attributes and is designed to be simple yet highly customizable.

### Requirements

The only real technical requirement besides jQuery itself, is declaring the HTML5 doctype for your web application. This is achieved by making sure the first line of your HTML is `<!doctype html>`. This ensures that using data attributes will be considered valid markup by browsers.

### Usage

For a simple example, consider this snippet of code:

``` html
<ul>
<li data-okimage='http://example.com/path/to/an/image.gif'>
<a href='#'>I'm a link</a>
</li>
</ul>
```

The above will have no visible effect. To achieve the hovering effect, you'll have to include this javascript after including the OKHover source.

``` js
$(function(){
$('li').okhover();
}):
```

When you hover on an `<li>`, you'll now see the okhover effect in action. The data attribute `data-image` is a reference to the image that will appear tiled in the background.

### Options

The following options are available to you:

<table>
<tbody>
<tr>
<th>option</th>
<th>description</th>
<th>default</th>
</tr>
<tr>
<td>fadeIn</td>
<td>A boolean that controls if the background image will fade in</td>
<td>false</td>
</tr>
<tr>
<td>fadeOut</td>
<td>A boolean that controls if the background image will fade out</td>
<td>false</td>
</tr>
<tr>
<td>fadeInDuration</td>
<td>A number that controls how long the fade-in will be (in milliseconds)</td>
<td>400 milliseconds</td>
</tr>
<tr>
<td>z-index</td>
<td>A number that controls the z-index of the background div</td>
<td>-1</td>
</tr>
</tbody>
</table>

Here's an example with a lot of options:

``` js
$(function(){
$('div').okhover({
fadeIn: true,
fadeOut: true,
fadeInDuration: 2000,
zIndex: 420
});
});
```

### Run Tests

OKFocus tests JavaScript with Jasmine. Run tests:

``` sh
$ bundle install
$ rake jasmine
```
62 changes: 0 additions & 62 deletions readme.textile

This file was deleted.

3 changes: 0 additions & 3 deletions src/okhover-1.0.3.min.js

This file was deleted.

27 changes: 14 additions & 13 deletions src/okhover-1.0.3.js → src/okhover.js
@@ -1,16 +1,16 @@
/*
* OKHover by OKFocus v1.1
* http://okfoc.us
*
* Copyright 2012, OKFocus
* Licensed under the MIT license.
*
*/

(function($){

$(function(){
$('body').append('<div id="ok-bg"></div>');
$('#ok-bg').css({
width : '100%',
height : '100%',
background : 'scroll 150% 150% repeat',
zIndex : -1,
position : 'fixed',
top : 0,
left : 0
});
$('body').append('<div id="ok-bg" style="width:100%;height:100%;background:scroll 150% 150% repeat;z-index:-1;position:fixed;top:0;left:0;"></div>');
});

$.okhover = function(el, options){
Expand Down Expand Up @@ -46,9 +46,10 @@
background.css('backgroundPosition', e.pageX + 'px ' + e.pageY + 'px');
});

background.css('backgroundImage', 'url(' + $(this).attr('data-okimage') + ')').show();
background.css('backgroundImage', 'url(' + $(this).attr('data-okimage') + ')');

if (base.options.fadeIn) background.stop().fadeTo(base.options.fadeInDuration, 1);
if (base.options.fadeIn) background.css('opacity', 0).stop().fadeTo(base.options.fadeInDuration, 1);
else background.show();
},
mouseout: function(){
if (base.options.fadeOut) background.stop().fadeTo(base.options.fadeOutDuration, 0, function() { $(this).css('backgroundImage', '').hide() });
Expand Down Expand Up @@ -82,4 +83,4 @@
});
};

})(jQuery);
})(jQuery);
11 changes: 11 additions & 0 deletions src/okhover.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbf8e23

Please sign in to comment.