Comments (6)
You're right… if a container element has been passed then this should only affect children of that container. Good catch! I'll push a fix soon 😄
from onscreen.
Btw for my own purposes I need only elements in the container to be selected, so (I think) I fixed it by changing the on
function.
I changed the line:
for (var i = 0, elems = document.querySelectorAll(selector); i < elems.length; i++) {
to:
for (var i = 0, elems = this.options.container.querySelectorAll(selector); i < elems.length; i++) {
from onscreen.
Nice, glad I could help this awesome project!
from onscreen.
@silvestreh Hey I got one quick question if you don't mind. OnScreen doesn't seem to support scrolling inside my container, since my container element has overflow:scroll
. When you scroll to the top of my container it triggers all the elements regardless of their vertical position in my container. Should it support this? I haven't dug into it yet to see if it's something I'm doing wrong but I thought I'd ask you first since you're around. Thanks!
from onscreen.
Ok well it seems like it was the case that there was some issues when container
had scrolling. I think I fixed it though. It wasn't easy :) Here's what I came up with. This replaces the last part of the inContainer
function:
var containerRect = options.container.getBoundingClientRect(),
elRect = el.getBoundingClientRect();
return (
// // Check bottom boundary
options.container.scrollTop + elRect.top + elRect.height - options.tolerance > containerRect.top + options.container.scrollTop &&
// Check right boundary
options.container.scrollLeft + elRect.left + elRect.width - options.tolerance > containerRect.left + options.container.scrollLeft &&
// Check left boundary
options.container.scrollLeft + elRect.left + options.tolerance < containerRect.left + containerRect.width + options.container.scrollLeft &&
// // Check top boundary
options.container.scrollTop + elRect.top + options.tolerance < containerRect.top + containerRect.height + options.container.scrollTop
);
Also with the changes to the querySelectorAll in my previous comments I had to add something like this in the on
event since window does not have a querySelectorAll method.
if (this.options.container === window) {
selected = document.querySelectorAll(selector);
}
else {
selected = this.options.container.querySelectorAll(selector);
}
I'm sure I haven't done things the best way, but hopefully it helps.
from onscreen.
Sorry for a bunch of messages. Just want to add that there's some issues with my updates when the container is not a scrolling element. I'll post the fix when I get to it.
from onscreen.
Related Issues (20)
- Bower support? HOT 12
- `on(event, selector, callback)` should support multi callbacks HOT 1
- First time leave event was not triggered on flex items HOT 5
- Example of destory HOT 3
- check IOS 6 Safari compatibility HOT 1
- Simplify `enter` / `leave` processing with callback: possible to pass the event type into the callback? HOT 3
- off() Method throws an error if trackedElements only has 'enter' or 'leave' HOT 6
- Debounce option is not used in debounced-scroll HOT 1
- Integration with React.js HOT 2
- a question
- Input: Improving scrolling performance HOT 1
- Events fire on page load, not on scroll HOT 2
- It doesn't seem that the check function works when the container is not window HOT 1
- the on.leave event seems not to be working HOT 1
- What about supporting Intersection Observer? HOT 2
- Ionic 3 Can't get this to work HOT 1
- Destroy does not remove MutationObserver HOT 1
- Typescript support HOT 4
- Option to not use debounced scrolling HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onscreen.