CSS-Tricks / AnythingSlider

A jQuery Slider plugin for anything.
http://css-tricks.github.io/AnythingSlider/
GNU Lesser General Public License v3.0
1.15k stars 380 forks source link

Caption issues/questions? #511

Closed jodriscoll closed 11 years ago

jodriscoll commented 11 years ago

Mottie, Is it possible to prevent the user from having the option to remove the caption by clicking it?

Second, I notice that if the user clicks the active slide, it reloads itself. How do I prevent the user from having the ability to load the slide they are currently viewing?

Mottie commented 11 years ago

If you look in the onInitialized function code, just remove the .click() portion to disable clicking (demo).

Before:

    onInitialized: function (e, slider) {
        slider.$items.each(function () {
            var cap = jQuery(this).find('.caption');
            cap.css('bottom', -cap.innerHeight()).click(function () {
                cap.animate({
                    bottom: (cap.css('bottom') === "0px" ? -cap.innerHeight() : 0)
                }, toggleTime);
            });
        });
        updateCaption(slider, true);
        slider.$controls.find('img').tooltip();
    },

After

    onInitialized: function (e, slider) {
        slider.$items.each(function () {
            var cap = jQuery(this).find('.caption');
            cap.css('bottom', -cap.innerHeight());
        });
        updateCaption(slider, true);
        slider.$controls.find('img').tooltip();
    },

As for clicking on the same slide making the caption animate a second time, just add this line:

if (!init && slider.currentPage === slider.targetPage) { return false; }

to the updateCaption function like this:

    updateCaption = function (slider, init) {console.log(slider);
        if (!init && slider.currentPage === slider.targetPage) { return false; }
        if (init && showCaptionInitially) {
            setTimeout(function () {
                slider.$targetPage.find('.caption').animate({
                    bottom: 0
                }, toggleTime);
            }, slider.options.delayBeforeAnimate + toggleTime);
        } else if (!init) {
            var cap = slider.$lastPage.find('.caption');
            cap.css('bottom', -cap.innerHeight());
        }
    };
jodriscoll commented 11 years ago

This fixed everything I needed! Thanks! :+1: