Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #23

Open
wants to merge 73 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
1e32ed7
Unify syntax, check whether element's in viewport via interval
Nov 22, 2010
b66094c
Further unified syntax, made the whole thing faster when no elements …
Nov 22, 2010
8ea24e2
Added tests, added support for horizontal scrolling, might be still b…
Nov 22, 2010
a32448e
Added example page and more tests
Nov 23, 2010
e2b0991
Added comment for isVisible logic
Nov 23, 2010
524e828
Moved if-condition for performance reasons
Nov 23, 2010
c7eeabf
Unified more syntax (tabs, quotes, ...), modified README, made test s…
Nov 24, 2010
8bb7dff
Smarter way of detecting whether element is in the DOM, switch back t…
Nov 24, 2010
66ecd43
More tests (for covering visiblePart parameters), more examples, bett…
Dec 15, 2010
87019b8
Extend browser compatibility section in README and fix typo in tests
Dec 15, 2010
11c30f9
Tests for live/delegate events, still failing though
Dec 21, 2010
8b3ed2a
Make sure that inview also works with delegate & live events
Dec 21, 2010
bf99b29
Unified variable namings
Dec 21, 2010
0eb44c3
Added comment explaining iOS quirks
Dec 21, 2010
e8c88b0
Example demonstrating live events
Dec 26, 2010
05e9e64
Updated tests and documentation of test results
Dec 26, 2010
1171f0b
Updated README: added link to demo and updated list of supported brow…
Jan 6, 2011
147a870
Added minified jquery.inview file
Jan 13, 2011
821f9df
only check visibility of inview live bindings, not of all
naltatis Feb 14, 2011
f09a76c
Updated minified version
Feb 14, 2011
a5a7552
jQuery 1.5 support, fixed global variable leakage, removed obsolete m…
Feb 16, 2011
38d4c4e
Smart way of running the unit tests in two jQuery versions with a sin…
Feb 16, 2011
15a04c8
Pimped setting of a variable
Feb 16, 2011
cb22af2
Had a look into jQuery 1.5 source code and found a better way of maki…
Feb 16, 2011
cd9d883
Saved a var in an each loop and updated minified version
Feb 16, 2011
2c3da2c
More tests, corrected variable usage in if condition (partially fixes…
Feb 21, 2011
0919f69
Fix minified version
Feb 24, 2011
bae761e
jQuery 1.6 support + Major refactoring
Jun 26, 2011
51d986a
Some performance improvements inspired by comments of 'Rafael Xavier …
Jun 26, 2011
85fa1ab
Further performance/minification optimizations
Jun 27, 2011
f35321c
Fix binding 'inview' to multiple elements at once (thx @gingerbeardman)
Jun 30, 2011
e3973f4
Removed console.log from qunit test
Jun 30, 2011
809f17f
Fix a strange Firefox 5 bug that causes a js error when switching bet…
Jul 11, 2011
90e95ea
Fix typo in comment
Jul 17, 2011
29a1c9e
Fix typos in README
tiff Aug 27, 2011
f5a2cc2
Use asyncTest() rather than test() and include jQuery 1.7rc1 in unit …
Oct 27, 2011
64cc212
Re-insert qunit reorder prevention
Oct 27, 2011
dd73e0c
Fix deprecated QUnit methods
Apr 1, 2012
cb1c17a
Update LICENSE :)
tiff Apr 1, 2012
e6bd902
Add jquery 1.8 to unit tests
tiff Sep 3, 2012
c6d0031
Add charset and ua-compatible meta tag to unit test suite
tiff Sep 4, 2012
f5300d6
Handle 'focus-scrolls' in IE < 9
tiff Oct 30, 2012
440a81a
Handle invisible (display: none;) elements
tiff Nov 28, 2012
8ba57f4
Revert "Handle invisible (display: none;) elements"
tiff Jan 16, 2013
d17d731
Make tests pass in jQuery 1.9
tiff Jan 16, 2013
a947ecc
Make the setInterval call conditional based on whether any elements a…
jrrudolph Nov 15, 2013
b2a2681
Merge pull request #20 from montanajob/setinterval-asneeded
tiff Dec 26, 2013
7d3ddce
Add bower.json
tiff Mar 15, 2014
ba71683
add jQuery Mobile compatibility
Jul 10, 2014
8db9ec1
Merge pull request #29 from shao1555/jquery-mobile-support
tiff Jul 18, 2014
f522556
use array instead of jQuery "add" method to improve performance when …
Jan 23, 2015
c313273
Merge pull request #39 from marktjagd/performance-improvements
tiff Jan 23, 2015
c15fbe0
Include package.json
Sep 15, 2015
8fc581e
AMD, CommonsJS and Global
Sep 15, 2015
5133162
Merge pull request #49 from jardix22/master
tiff Oct 1, 2015
be2769f
* Support for jQuery 2.2+
tiff Jan 26, 2016
c3c6929
Release v1.1.0
tiff Jan 26, 2016
3b7dddf
Update README
tiff Jan 26, 2016
c56dae9
Show correct version in README
tiff Jan 26, 2016
e01a41f
exclude example and test from npm
tiff Jan 26, 2016
dd4be9e
Update README
tiff Jan 26, 2016
d5d6f90
Update README
tiff Jan 26, 2016
0cfa997
Update README
tiff Jan 26, 2016
5b2f835
Update version in package.json
tiff Jan 26, 2016
e031f5b
Use offsetWidth/offsetHeight rather than jquery's methods
tiff Jan 26, 2016
037f8eb
v1.1.2
tiff Jan 26, 2016
601a0e1
Update bower.json
tiff Jan 28, 2016
5a4dc9f
Fix: inview breaks scrollstop & lazyload plugins
Mar 28, 2016
6a34550
Merge pull request #54 from codepodu/master
tiff Mar 28, 2016
56cbe38
README.md: made the description of .one() clearer
hi2u Mar 24, 2017
8973967
[bower] - fix illegal character
Jul 27, 2017
1665d4a
Merge pull request #65 from CHEWX/master
tiff Jul 29, 2017
6f11936
Merge pull request #61 from hi2u/patch-1
tiff Jul 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tm_sync.config
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/
example/
46 changes: 9 additions & 37 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

http://creativecommons.org/licenses/by-nc-sa/2.0/uk/
Copyright (C) 2004 Sam Hocevar <[email protected]>

You are free:
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

* to copy, distribute, display, and perform the work
* to make derivative works


Under the following conditions:

* Attribution — You must give the original author credit.
Attribute this work:
Information
What does "Attribute this work" mean?
The page you came from contained embedded licensing metadata,
including how the creator wishes to be attributed for re-use.
You can use the HTML here to cite the work. Doing so will
also include metadata on your page so that others can find the
original work as well.

* Non-Commercial — You may not use this work for commercial
purposes.
* Share Alike — If you alter, transform, or build upon this
work, you may distribute the resulting work only under a
licence identical to this one.

With the understanding that:

* Waiver — Any of the above conditions can be waived if you get
permission from the copyright holder.
* Other Rights — In no way are any of the following rights
affected by the license:
o Your fair dealing or fair use rights;
o The author's moral rights;
o Rights other persons may have either in the work itself
or in how the work is used, such as publicity or privacy rights.
* Notice — For any reuse or distribution, you must make clear to
others the licence terms of this work.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Element 'inview' Event Plugin

Event that is fired as soon as an element appears in the user's viewport.

* **Author:** [Christopher Blum](http://twitter.com/ChristopherBlum)
* **Original idea and concept by:** [Remy Sharp](http://remysharp.com/2009/01/26/element-in-view-event-plugin/)
* **Forked from:** [https://github.com/zuk/jquery.inview/](https://github.com/zuk/jquery.inview/)
* **Requires:** jQuery 1.8+

## Usage

The script makes use of the new $.contains method - so it will only work with jQuery 1.8 upwards. If you need to use it with older versions of jQuery, drop a comment, and I'll post an alternative.

The event will only fire when the element comes in to view of the viewport, and out of view. It won't keep firing if the user scrolls and the element remains in view.

The variable after the event argument indicates the visible state in the viewport.

$('div').on('inview', function(event, isInView) {
if (isInView) {
// element is now visible in the viewport
} else {
// element has gone out of viewport
}
});

To stop listening for the event - simply unbind:

$('div').off('inview');

If you would like the event only to trigger once per element while the page is loaded, you can use the .one() method instead of .on():

$('div').one('inview', ...);

Live events

Yep, inview events can also be used with .on/.delegate methods.
*Please note that this could slow down your app when the selector is too complex and/or matches a huge set of elements.*
The following code snippet only loads images when they appear in the browser's viewport.

// Assuming that all images have set the 'data-src' attribute instead of the 'src'attribute
$("body").on("inview", "img[data-src]", function() {
var $this = $(this);
$this.attr("src", $this.attr("data-src"));
// Remove it from the set of matching elements in order to avoid that the handler gets re-executed
$this.removeAttr("data-src");
});

## Use cases

* Reduce http requests and traffic on server by loading assets (images, javascript, html, ...) only when they are visible to the user
* Endless scrolling (twitter-like)
* Tracking (eg. to see whether a user has read an entire article)
* ...

## Browser Compatibility

The Test Suite succeeds in the following browsers that were tested:

* Firefox 3+
* Safari 3+
* Chrome 7+
* Opera 10+
* IE 6+
* Mobile Safari on iPad 4.2.2
119 changes: 0 additions & 119 deletions README.textile

This file was deleted.

6 changes: 6 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "protonet.jquery.inview",
"version": "1.1.2",
"main": "jquery.inview.js",
"description": "jQuery event that is fired as soon as an element appears in the user's viewport."
}
46 changes: 46 additions & 0 deletions example/advanced.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>jquery.inview - Example</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width, height=device-height">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="../jquery.inview.js"></script>
<style>
body {
font-family: Arial, Verdana, sans-serif;
font-size: 12px;
position: relative;
width: 5000px;
height: 5000px;
}
#abs-element {
left: 50%;
top: 50%;
position: absolute;
width: 200px;
height: 100px;
border: 2px solid red;
margin-top: -52px;
margin-left: -102px;
}
</style>
</head>
<body>
Scroll to the <a href="#abs-element">middle</a> of this page!
<div id="abs-element">
<div>visiblePartX: <span id="visible-part-x"></span></div>
<div>visiblePartY: <span id="visible-part-y"></span></div>
</div>

<script>
$('#abs-element').bind('inview', function(event, visible, visiblePartX, visiblePartY) {
if (visible) {
$('#visible-part-x').html(visiblePartX);
$('#visible-part-y').html(visiblePartY);
} else {
$('#visible-part-x, #visible-part-y').html('');
}
});
</script>
</body>
</html>
Loading