diff --git a/MIT-LICENSE.txt b/LICENSE.md similarity index 86% rename from MIT-LICENSE.txt rename to LICENSE.md index 7f1e8a2..e686bdf 100644 --- a/MIT-LICENSE.txt +++ b/LICENSE.md @@ -1,3 +1,7 @@ +jQuery v1 is released under the MIT license described below. jQuery v2 is +under development and may be released under a different licensing model, +including a commercial option. + Copyright 2014 Jonathon Menz and other contributors, https://github.com/jonom/jquery-focuspoint diff --git a/README.md b/README.md index 5879064..82dce4d 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,16 @@ -# jQuery FocusPoint +# jQuery FocusPoint 2 -## FocusPoint 2 +**Note:** This branch is currently under development and and is not intended for production use. The licensing model may change for version 2 and a commercial license may be required for use in commercial projects. This is intended to ensure I can continue to support this project in a sustainable fashion and is likely to be inexpensive. Contributions are welcome as long as you are comfortable with this potential change. -I started work on a major update to this plugin a couple of years ago, but it has been in limbo for a while and probably won't be picked up again unless someone wants to sponsor the work (please [get in touch](http://jonathonmenz.com) if you do!). I didn't get as far as removing the jQuery dependancy but please feel free to use the v-2-dev branch to benefit from a few new features: +## Art direction for flexible image containers -* Better resizing performance -* More familiar coordinate system (like that used in CSS) -* Suppor for ideal and minimum cropping region - -If you love this plugin feel free to send me an encouraging email or consider sponsoring an update. You're also welcome to make a [small donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VUDD3ACRC4TC) if you like. I receive an average of one per year, so it won't go unnoticed. 😄💰 - -## Intelligent cropping for flexible image containers - - + Websites don't have a single layout any more. The space you have for an image may be portrait on a laptop, landscape on a tablet, and square on a mobile - particularly if you're using a full-screen image. If you have to use the same image file in all these contexts, you might not be happy with the results you get when you 'fill' the allocated space with your image. Your subject might be clipped or completely missing, or just really awkward looking. -FocusPoint makes sure your image looks great in any container, by ensuring the 'spare' parts of your image (negative space) are cropped out before the important parts. +FocusPoint makes sure your image looks great in any container, by ensuring the most important part of your image always stays within the frame. For a quick overview of the plugin check out this [video by Petr Tichy](http://youtu.be/Wxmxsw65BQw?t=6m49s). @@ -26,29 +18,36 @@ For a quick overview of the plugin check out this [video by Petr Tichy](http://y Here are some examples showing the same image cropped a variety of different ways at once. Make sure you play with resizing the browser window to get a feel for what FocusPoint does. -* [Lizard](http://jonom.github.io/jquery-focuspoint/demos/grid/lizard.html) -* [Kangaroo](http://jonom.github.io/jquery-focuspoint/demos/grid/kangaroo.html) -* [Dolphin](http://jonom.github.io/jquery-focuspoint/demos/grid/dolphin.html) -* [Bird](http://jonom.github.io/jquery-focuspoint/demos/grid/bird.html) +* [Lizard](http://jonom.github.io/jquery-focuspoint/demos/grid/lizard.html) +* [Kangaroo](http://jonom.github.io/jquery-focuspoint/demos/grid/kangaroo.html) +* [Dolphin](http://jonom.github.io/jquery-focuspoint/demos/grid/dolphin.html) +* [Bird](http://jonom.github.io/jquery-focuspoint/demos/grid/bird.html) And here is a [full screen](http://jonom.github.io/jquery-focuspoint/demos/full-screen/index.html) demo. +## In the wild + +FocusPoint helps with art direction on [Adele's website](http://adele.com/home/). + +Are you using FocusPoint on a cool or high profile website? [Let me know!](http://jonathonmenz.com) + ## How does it work? The idea is that most images have a focal point or subject that is the most important part of the image. In the case of a traditional portrait photo this would be the subject's face (or specifically the spot right between their eyes). In the image above it's arguably the point halfway between the two people's faces. FocusPoint requires you to indicate where this focal point is located within your image, and then works in the background to ensure that point is never cropped out. - ## How to use #### 1. Calculate your image's focus point -An image's focus point is made up of x (horizontal) and y (vertical) coordinates. The value of a coordinate can be a number with decimal points anywhere between -1 and +1, where 0 is the centre. X:-1 indicates the left edge of the image, x:1 the right edge. For the y axis, y:1 is the top edge and y:-1 is the bottom. +An image's focus point is made up of `x` (horizontal) and `y` (vertical) coordinates. The value of a coordinate can be a decimal point number anywhere between `0` and `1` and works similar to positioning in CSS. On the `x` axis `0` means the left edge and `1` means the right, while on the `y` axis `0` means the top and `1` means the bottom. On both axes `0.5` indicates the center. - + -**Confused?** Don't worry, there's a handy script included to help you find the focus coordinates of an image with a single click. Check out the [helper tool](http://jonom.github.io/jquery-focuspoint/demos/helper/index.html) *(vastly improved courtesy of [@auginator](https://github.com/auginator)).* +*Note: Version 1 of this plugin used a different grid and coordinate system. If you like you can keep using the old system by using the `legacyGrid` setting (see below).* + +**Sound hard?** Don't worry, you can easily find the focus point coordinates of any image by using the [helper tool](http://jonom.github.io/jquery-focuspoint/demos/helper/index.html) *(courtesy of [@auginator](https://github.com/auginator)).* #### 2. Include javascript and CSS @@ -67,7 +66,7 @@ Specify the image dimensions and focus point coordinates on the image container. ```html
@@ -93,14 +92,15 @@ FocusPoint comes with a few options you can change to suit your needs.
| Option | Values | Default | Description |
| ---------------------- | --------------------- | ------- | ----------- |
-| `reCalcOnWindowResize` | `true` or `false` | `true` | Whether or not to re-adjust image when the window is resized |
-| `throttleDuration` | Int e.g. `0` or `100` | `17` | Throttling rate in milliseconds. Set to `0` to disable throttling. |
+| `reCalcOnWindowResize` | `true` or `false` | `true` | Whether or not to re-adjust image when the window is resized. |
+| `setTransformOrigin` | `true` or `false` | `true` | Whether or not to set the images transform origin to match the focus point. This allows for easy zooming from the focus point with css transforms. |
+| `legacyGrid` | `true` or `false` | `false` | Set to true to use FocusPoint v1 style coordinates and grid system. |
Example usage:
```javascript
$('.focuspoint').focusPoint({
- throttleDuration: 100 //re-focus images at most once every 100ms.
+ reCalcOnWindowResize: false // Don't automatically follow window resize event
});
```
@@ -112,10 +112,20 @@ Or the shorter way, like this: `$(someContainer).focusPoint('methodName')`
| Function | Description |
| --------------- | ----------- |
-| `adjustFocus()` | Re-do calculations and re-position an image in it's frame. Call if container dimensions change. |
-| `windowOn()` | Start window event listener and re-focus image when window is resized |
+| `adjustFocus()` | Re-do calculations and re-position an image in it's frame. Should be called when container dimensions change. |
+| `windowOn()` | Start window event listener to automatically re-focus this image when window is resized |
| `windowOff()` | Stop re-focusing image when window is resized |
+## Advanced usage
+
+#### Minimum cropping region
+
+Suppose you have an image that looks okay in a square or portrait frame, but it really doesn't work in a landscape container, due to lack of vertical negative space in the image. In that case you might want the image to fill the frame for square or portrait aspect ratios, but only partially fill the frame in landscape ones. You can do this by specifying a minimum cropping region. All you need to do is pass two comma separated `x` coordinates and/or two `y` coordinates instead of one.
+
+
+
+[See an example](http://jonom.github.io/jquery-focuspoint/demos/test/index.html)
+
#### Using FocusPoint in content sliders
Currently FocusPoint can't do it's calculations properly if an image container or it's parent is set to `display:none`, as it won't have any dimensions. This can cause problems with sliders that hide non-active slides. A work-around for now is to trigger `adjustFocus()` on the image container as soon as it become visible.
@@ -148,24 +158,6 @@ If FocusPoint helped you impress a client and you want to say thanks, you're wel
[
](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5VUDD3ACRC4TC)
-Donations received / Warm fuzzies generated: **6**
-Caffé Lattes funded: **17** :coffee: :relieved:
+Donations received / Warm fuzzies generated: **6**
+Caffé Lattes funded: **17** :coffee: :relieved:
**Thanks!** Daniil, Cohan, Romulo, Lemuel, David
-
-## Changelog
-
-#### v1.1.1 2014-09-23
-Minor fixes
-#### v1.1.0 2014-09-18
-Refactored code (thanks @xat)
-Added ability to start/stop window-resize listener (thanks @xat)
-Use % instead of px for positioning, for better scaling
-Added shortcuts to plugin methods
-#### v1.0.3 2014-09-06
-Throttled window resize updates
-#### v1.0.2 2014-09-05
-Made setting image width and height on shell optional (thanks @luruke)
-#### v1.0.1 2014-09-04
-Cleaned up variables
-#### v1.0.0 2014-08-19
-Initial release
diff --git a/css/focuspoint.css b/css/focuspoint.css
index 7305b50..f4d9bc1 100755
--- a/css/focuspoint.css
+++ b/css/focuspoint.css
@@ -4,14 +4,20 @@
position: relative; /*Any position but static should work*/
overflow: hidden;
}
-.focuspoint img {
+.focuspoint img,
+.focuspoint video {
position: absolute;
left: 0;
top: 0;
margin: 0;
display: block;
- /* fill and maintain aspect ratio */
+ /* fill and maintain aspect ratio without JS */
width: auto; height: auto;
min-width: 100%; min-height: 100%;
max-height: none; max-width: none;
+}
+.focuspoint-active img,
+.focuspoint-active video {
+ min-width: 0;
+ min-height: 0;
}
\ No newline at end of file
diff --git a/demos/css-js-comparison/index.html b/demos/css-js-comparison/index.html
index bb53ef0..9005b8c 100644
--- a/demos/css-js-comparison/index.html
+++ b/demos/css-js-comparison/index.html
@@ -35,8 +35,8 @@
diff --git a/demos/full-screen/index.html b/demos/full-screen/index.html
index 09fc000..051bb23 100644
--- a/demos/full-screen/index.html
+++ b/demos/full-screen/index.html
@@ -33,8 +33,8 @@
diff --git a/demos/grid/bird.html b/demos/grid/bird.html
index 63990bf..5fc7b27 100644
--- a/demos/grid/bird.html
+++ b/demos/grid/bird.html
@@ -35,72 +35,72 @@
diff --git a/demos/grid/dolphin.html b/demos/grid/dolphin.html
index cdeb36b..a5b97c1 100644
--- a/demos/grid/dolphin.html
+++ b/demos/grid/dolphin.html
@@ -41,72 +41,72 @@
diff --git a/demos/grid/grid.css b/demos/grid/grid.css
index f451a26..7baef30 100755
--- a/demos/grid/grid.css
+++ b/demos/grid/grid.css
@@ -22,7 +22,9 @@ body {
position: absolute;
overflow: hidden;
border: 5px solid #fff;
- margin: -5px 0 0 -5px;
+ background: #ccc;
+ box-shadow: inset 0px 0px 65px rgba(0, 0, 0, 0.4);
+ box-sizing: border-box;
}
#Frame1, #Frame4, #Frame7 {
width: 66.6666667%;
diff --git a/demos/grid/ideal-cropping-region.html b/demos/grid/ideal-cropping-region.html
new file mode 100644
index 0000000..c15c009
--- /dev/null
+++ b/demos/grid/ideal-cropping-region.html
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+ Try resizing the window. The image will fill each frame as much as it can, until that would prevent all of the minimum cropping region being shown. » Project Home
+
diff --git a/demos/grid/lizard.html b/demos/grid/lizard.html
index 2bd02cd..612d4b0 100644
--- a/demos/grid/lizard.html
+++ b/demos/grid/lizard.html
@@ -35,72 +35,72 @@
diff --git a/demos/grid/min-cropping-region.html b/demos/grid/min-cropping-region.html
new file mode 100644
index 0000000..de357a4
--- /dev/null
+++ b/demos/grid/min-cropping-region.html
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Try resizing the window. The image will fill each frame as much as it can, until that would prevent all of the minimum cropping region being shown. » Project Home
+FocusPoint Tests » Project Home
-
+
+
+
- Missing image-w and image-h
+
+
+
- Slow redraw (high throttleDuration)
+
+
+
- No throttling
+
+
+
+
+
+