首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >anythingSlider -标题不再具有动画效果

anythingSlider -标题不再具有动画效果
EN

Stack Overflow用户
提问于 2013-03-15 04:56:16
回答 1查看 339关注 0票数 0

我已经开始在jsFiddle项目中设置皮肤、配置和实现anythingSlider,并且我注意到,一旦我实现了缩略图/滑块系统,我的字幕就不再在转换/加载时显示动画。javaScript框中的jQuery可能相互冲突。

你可以在这里查看小提琴:http://jsfiddle.net/jodriscoll/fKCFE/

理论上,标题应该从图像下面滑入,并显示幻灯片本身的onLoad /从一张幻灯片过渡到另一张幻灯片。

下面是一个我喜欢的工作方式的例子:http://jsfiddle.net/jodriscoll/fKCFE/51/

代码语言:javascript
复制
// caption toggle animation time
var toggleTime = 500,
// always show caption when slide comes into view
showCaptionInitially = true,

updateCaption = function(slider, init) {
    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());
    }
};

$('#slider').anythingSlider({
//  buildNavigation : false,
// *********** Callbacks ***********
// Callback when the plugin finished initializing
onInitialized: function(e, slider) {
    slider.$items.each(function() {
        var cap = $(this).find('.caption');
        cap.css('bottom', -cap.innerHeight()).click(function() {
            cap.animate({
                bottom: (cap.css('bottom') === "0px" ? -cap.innerHeight() : 0)
            }, toggleTime);
        });
    });
    updateCaption(slider, true);
},

// Callback before slide animates
onSlideBegin: function(e, slider) {
    updateCaption(slider, true);
},

// Callback after slide animates
onSlideComplete: function(slider) {
    updateCaption(slider, false);
}
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-15 09:43:15

问题是那个滑块被初始化了两次。第二个实例中的任何代码都将被忽略。这是一个updated demo,其中的代码由两者组合而成。

代码语言:javascript
复制
// ******************
// Thumnail Slider
// ******************
var fadeTime = 0,
    fadeDelay = 0,
    timer,
    hideControls = function (slider) {
        clearTimeout(timer);
        setTimeout(function () {
            slider.$controls.fadeOut(fadeTime);
            $('.tooltip').fadeOut(fadeTime);
        }, fadeDelay);
    },
    // ******************
    // Caption animation
    // ******************
    toggleTime = 500,
    showCaptionInitially = true,
    updateCaption = function (slider, init) {
        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());
        }
    };

$('#slider').anythingSlider({
    navigationSize: 3,
    navigationFormatter: function (i, panel) {
        var url = 'http://www.massgeneral.org/international/dev/assets/slideshow/slideshow-',
            thumbs = [
                ['01', 'This is the tooltip for the first thumbnail'],
                ['02', 'This is the tooltip for the second thumbnail'],
                ['03', 'This is the tooltip for the third thumbnail'],
                ['04', 'This is the tooltip for the fourth thumbnail'],
                ['05', 'This is the tooltip for the fifth thumbnail'], ];
        return '<img title="' + thumbs[i - 1][1] + '" src="' + url + thumbs[i - 1][0] + '.jpg">';
    },
    onInitialized: function (e, slider) {
        slider.$items.each(function () {
            var cap = $(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();
    },
    onSlideBegin: function (e, slider) {
        updateCaption(slider, true);
    },
    onSlideComplete: function (slider) {
        updateCaption(slider, false);
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15420016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档