protonet / jquery.inview

A jQuery plugin that adds a bindable 'inview' event for detecting when an element is scrolled into view.
blog.protonet.info/post/2516624585/jquery-inview-plugin
Do What The F*ck You Want To Public License
1.67k stars 488 forks source link

Making This Work in an iFrame #73

Open brittonk opened 6 years ago

brittonk commented 6 years ago

I'm working on an app which this script works great on. Unfortunately, I've had to enclose everything in an iframe so that I can keep user uploads (photos/videos) continuing across page change in the app.

When inside the iframe, inview no longer works. Would there be an easy fix to get it to watch the iframe's content viewport?

sadikyalcin commented 5 years ago

You can try this. Not sure if it will work as first time I'm using this library now and trying it out.

var iframe = $('iframe');
var yourElement = $(iframe).contents().find('.yourelement');

$(yourElement).on('inview', function(event, isInView) {
    if (isInView) {
        // in-view
    } else {
        // off-view
    }
});