Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

Scroll to close doesn't work like in Medium #194

Open
elron opened this issue Dec 18, 2017 · 4 comments
Open

Scroll to close doesn't work like in Medium #194

elron opened this issue Dec 18, 2017 · 4 comments

Comments

@elron
Copy link

elron commented Dec 18, 2017

Hey,
I tried to open the demo in chrome + edge but whenever I scroll when there's a picture open, it doesn't close it.
Notice how in Medium's site you can scroll up or down, and it will close it after like 500ms, but it doesn't work in Fluidbox.
I've seen this comment but its not identical to how Medium fluidbox behaves. See, in Medium you can scroll up to 60 pixels down/up but nothing happens. only when you cross that 60 pixels, it fires the close event.

Will this be fixed?
Other than that its really awesome!!
I appreciate your work!
Elron

@terrymun
Copy link
Owner

The comment you have linked is a good place to start: you can always modify it to suit your needs (in this case, an exact Medium replica in terms of UX). Fluidbox is not meant to be a verbatim copy of Medium's lightbox component, but more of a study of it. It is extremely minimal and stripped down, but powerful in the sense that it emits a lot of events that you can use as hooks for calling custom methods.

So, this is not a bug per se that has to be fixed ;)

@elron
Copy link
Author

elron commented Dec 19, 2017

I see :) thanks for your detailed answer!
Is the plugin extendable? for example, if I want to add another JS with that event feature without breaking or changing your original code - is that possible? (having the fluidbox-main.js file and the fluidbox-extension.js)

@terrymun
Copy link
Owner

terrymun commented Dec 20, 2017

The plugin does not allow you to register custom events, but you can feel free to create a fork and merge in the master branch whenever it is updated.

Speaking of your original question, a slightly modification to the code snippet you linked should work (I have not tested it tho):

// Initialise Fluidbox
$('a').fluidbox();

// Listen to scroll
// Note: You might want to throttle the callback, e.g.:
// - Use jQuery throttle/debounce plugin
// - Use underscore/lodash _.throttle
var scrollPosition;
$(window).scroll(function() {
    var currentScrollPosition = $(window).scrollTop();
    
    // If has scrolled beyond plus/minus 60 pixels
    if (Math.abs(currentScrollPosition - scrollPosition) > 60)
    	$('a').fluidbox('close');

    // Update global scroll position store
    scrollPosition = currentScrollPosition;
});

@elron
Copy link
Author

elron commented Dec 20, 2017

oh thats genius! thanks.
Haven't tested it yet but it looks neat.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants