ThemeForest

Disable Lightbox on Small Screens

228 posts
  • Sold between 5 000 and 10 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 100 and 199 users
  • Bought between 10 and 49 items
  • Microlancer Beta Tester
  • Has been a member for 2-3 years
  • Exclusive Author
  • Portugal
vtimbuc says

Hey guys,

I need your help to disable the prettyphoto lightbox if the width of the window is smaller than 768px.

With this code when the window is smaller I can disable the lightbox, but when I make it bigger I don’t know how to make the lightbox work again.

$(window).resize(function () {
    if ( $(window).width() <= 767 ) {
        $('a[rel^="lightbox"]').unbind('click').on('click', function (event) {
            event.preventDefault();
        });
    } else {
        $('a[rel^="lightbox"]').bind('click');
    }
});

Thanks

4 posts
  • Exclusive Author
  • Has been a member for 2-3 years
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Europe
  • Sold between 10 000 and 50 000 dollars
templatestock says

Hello,

I know it’s probably an outdated post, but here is my solution for mobile devices & colorbox. Maybe it gets handy for someone else.

(function ($){

    $(function (){

        /* Disable Colorbox on mobile devices */

        $mobile_colorbox();

        $(window).resize(function () {
            $mobile_colorbox()
        });

    });

    $mobile_colorbox = function ()
    {
        if ( $(window).width() <= 767 ) {
            $('.colorbox').colorbox.remove();
        } else {
            $('.colorbox').colorbox({rel:'colorbox'});
        }            
    }

})(jQuery);

See how the mobile_colorbox is called on page load and then again on window resize.

2 posts
  • Has been a member for 0-1 years
akoola says

sorry, i don’t see where it ” is called on page load ”.

4 posts
  • Exclusive Author
  • Has been a member for 2-3 years
  • Bought between 10 and 49 items
  • Referred between 50 and 99 users
  • Europe
  • Sold between 10 000 and 50 000 dollars
templatestock says

right after $(function (){

there is a function call $mobile_colorbox();

$(function (){}) is a default jquery function that awaits all dom to be loaded.


sorry, i don’t see where it ” is called on page load ”.
2 posts
  • Has been a member for 0-1 years
akoola says

got it, thx

by
by
by
by
by