Back & Next by Clicking on Image

7 messages Options
Embed this post
Permalink
fluxstate

Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
Is there any way (in CSS or JS) to create an overlay that by clicking on the right side of the image, it goes to the next image using Shadowbox.next() and clicking on the left side goes to previous image using Shadowbox.previous().

I don't like how the little nav buttons move around as the images resizes and would rather have people just click on the images to move around.

Kind of like Slimbox:
http://www.digitalia.be/demo/slimbox/

Matt50

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
This would be a great addition to shadowbox - can't find any solutions in the forum and my javascript skills are not up to the task!

One for the feature requests..
zychu

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
In reply to this post by fluxstate
open your skin file (javascript) and modify this line:

                        '<div id="shadowbox_body" >' +

to this:

                        '<div id="shadowbox_body" onclick="Shadowbox.next()">' +

it's work for me.

If you want previous and next buttons , just create two divs inside shadowbox body with 50%  width (set this in css) and add onclick event to all of them with concrete value.
Mez

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
Can you give me more explainations about how to change the .js and .css ... I'm a js newbie.

Thanks a lot
Mez

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
I propose to had the line : cursor: pointer into the skin.css file (tag: #shadowbox_body).

So people will know that a clic is possible on the picture.
John

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
If you have no skin/use the default one, you go like this:

Open shadowbox.js and locate <div id="sb-body">  and change it to <div id="sb-body" onclick="Shadowbox.next()". Don't forget to clear cache/temporary intenret files before trying it  out...
Ambient.Impact

Re: Back & Next by Clicking on Image

Reply Threaded More More options
Print post
Permalink
I've managed to do add custom next/previous and close controls to Shadowbox without actually modifying the source (which makes upgrades easier). There are some settings and functions specific to my project, but this should get you started. I use jQuery heavily in all my projects, as you can see. I also use conditional compilation to give IE special treatment, as that's the only 100% foolproof way to detect it, and not another browser masquerading as it.

JavaScript

(function() {
        // ---- Shadowbox setup ----
        var openInit = false;
        var titleAnimationActive = false;

        var navFadeInTime = 150;
        var navFadeOutTime = 400;
        var navMinOpacity = 0.1;
        var navMaxOpacity = 1;

        var closeFadeInTime = 150;
        var closeFadeOutTime = 400;
        var closeMinOpacity = false;
        var closeMaxOpacity = 1;

        Shadowbox.init({
                skipSetup: true,
                initialWidth: 100,
                initialHeight: 100,
                //counterType: 'skip',
                //displayCounter: false,
                displayNav: false,
                onOpen: function(galleryElement) {
                        var $this = $(galleryElement.el);

                        titleAnimationActive = site.titleAnimation.isActive();
                        if (titleAnimationActive && site.settings.stopTitleWhileViewerOpen) {
                                site.titleAnimation.stop();
                        }

                        if (!$('#sb-custom-close').length) {
                                // Create our own close link
                                var $closeLink = $(site.createPseudoLink('Close '))
                                .attr('id', 'sb-custom-close')
                                .attr('title', 'Close')
                                .bind('click', function(event) {
                                        Shadowbox.close();
                                })
                                .appendTo('#sb-title');
                                // Grab initial opacity from stylesheet
                                // !IMPORTANT! - IE doesn't like this, ignoring it down below
                                closeMinOpacity = $closeLink.css('opacity');
                        }

                        openInit = false;
                },
                onFinish: function(galleryElement) {

                        // Overlay next/previous links over image
                        // TO DO: only display if content type is "img"?
                        var $nextLink = $(site.createPseudoLink('Next '))
                        .attr('id', 'sb-custom-nav-next')
                        .addClass('sb-custom-nav-link')
                        .one('click', function(event) {
                                Shadowbox.next();
                        }).css({opacity: navMinOpacity});
                        if (!Shadowbox.hasNext()) {
                                $nextLink.addClass('unused');
                        }
                        var $previousLink = $(site.createPseudoLink('Previous '))
                        .attr('id', 'sb-custom-nav-previous')
                        .addClass('sb-custom-nav-link')
                        .one('click', function(event) {
                                Shadowbox.previous();
                        }).css({opacity: navMinOpacity});
                        if (Shadowbox.current == 0) {
                                $previousLink.addClass('unused');
                        }

                        var $navLinks = $([$nextLink[0], $previousLink[0]]);
                        $('#sb-body-inner').append($navLinks);

                        // Fade in and out on mouse over and out, respectively
                        $navLinks
                        .hover(function(event) {
                                $(this).stop(true).animate({opacity: navMaxOpacity}, navFadeInTime);
                        }, function(event) {
                                $(this).animate({opacity: navMinOpacity}, navFadeOutTime);
                        });

                        // Flash and then slowly fade nav links to make user aware of them
                        $navLinks
                        .animate({opacity: navMaxOpacity}, navFadeInTime)
                        .animate({opacity: navMinOpacity}, navFadeOutTime * 3);

                        var $closeLink = $('#sb-custom-close');

                        // IE 8 and lower can't read initial opacity, so don't fade
                        /*@cc_on if ($.browser.version > 8) { @*/
                                $closeLink
                                .hover(function(event) {
                                        $(this).stop(true).animate({opacity: closeMaxOpacity}, closeFadeInTime);
                                }, function(event) {
                                        $(this).animate({opacity: closeMinOpacity}, closeFadeOutTime);
                                })
                                .animate({opacity: closeMaxOpacity}, closeFadeInTime)
                                .animate({opacity: closeMinOpacity}, closeFadeOutTime * 3);
                        /*@ } @*/

                        openInit = true;
                },
                onClose: function(galleryElement) {
                        if (titleAnimationActive && site.settings.stopTitleWhileViewerOpen) {
                                site.titleAnimation.start();
                        }
                }
        });
})();


CSS

/* Custom image locations, overriding shadowbox.css properties */
#sb-nav-close {
  background-image: url(../images/shadowbox/close.png);
}
#sb-nav-next {
  background-image: url(../images/shadowbox/next.png);
}
#sb-nav-previous {
  background-image: url(../images/shadowbox/previous.png);
}
#sb-nav-play {
  background-image: url(../images/shadowbox/play.png);
}
#sb-nav-pause {
  background-image: url(../images/shadowbox/pause.png);
}
/* Custom loading throbber */
#sb-loading {
        background-image: url(../images/throbber.gif);
        background-position: 50% 50%;
        background-repeat: no-repeat;}
#sb-loading a {
        display: none !important;
}

#sb-title-inner {
        font-weight: bold;
}

/* Custom navigation pseudo-links */
#sb-custom-nav-next,
#sb-custom-nav-previous {
        position: absolute;
        display: block;
        top: 0;
        height: 100%;
/* width: 30%;
        min-*/width: 96px;
        text-indent: -999em;
        overflow: hidden;
}
#sb-custom-nav-next {
        right: 0;
}
#sb-custom-nav-previous {
        left: 0;
}
#sb-custom-nav-next.unused,
#sb-custom-nav-previous.unused {
        display: none;
}
#sb-custom-nav-next .nav-icon,
#sb-custom-nav-previous .nav-icon {
        display: block;
        position: absolute;
        top: 50%;
        margin-top: -64px;
        width: 48px;
        height: 128px;
        background: transparent url(../images/viewer_nav.png) 0 0 no-repeat;
        opacity: 0.6; /* See common_ie.css as well */
}
.IE6 #sb-custom-nav-next .nav-icon,
.IE6 #sb-custom-nav-previous .nav-icon {
        background-image: url(../images/viewer_nav_ie6.png);
}
#sb-custom-nav-next .nav-icon {
        background-position: -48px 0;
        right: 24px;
}
#sb-custom-nav-previous .nav-icon {
        left: 24px;
}

/* Custom close pseudo-link */
#sb-custom-close {
        top: 0;
        right: 0;
        text-indent: -999em;
        overflow: hidden;
        opacity: 0.5; /* See common_ie.css as well */
}
#sb-custom-close,
#sb-custom-close .close-icon {
        position: absolute;
        display: block;
        width: 24px;
        height: 24px;
}
#sb-custom-close .close-icon {
        top: 0;
        left: 0;
        background: transparent url(../images/viewer_close.png) 0 0 no-repeat;
}
.IE6 #sb-custom-close .close-icon {
        background-image: url(../images/viewer_close_ie6.png);
}