Search code examples
jquerymagnific-popup

Magnific Popup - Disable arrows on first/last items


I'm using magnific-popup and I am wondering if there is a way to disable the arrows on the first/last item in a gallery.

I have read through the documentation, but cannot find anything about this kind of functionality.


Solution

  • You don't need to modify any source files, you can just override prev/next functions:

    callbacks: {
        open: function() {
            var mfp = $.magnificPopup.instance;
            var proto = $.magnificPopup.proto;
    
            // extend function that moves to next item
            mfp.next = function() {
    
                // if index is not last, call parent method
                if(mfp.index < mfp.items.length - 1) {
                    proto.next.call(mfp);
                } else {
                   // otherwise do whatever you want, e.g. hide "next" arrow
                }
            };
    
            // same with prev method
            mfp.prev = function() {
                if(mfp.index > 0) {
                    proto.prev.call(mfp);
                }
            };
    
        }
    }
    

    http://dimsemenov.com/plugins/magnific-popup/documentation.html#how_to_override_some_function_without_modifying_the_source_files