首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jQuery循环在容器上自动设置高度

使用jQuery循环在容器上自动设置高度
EN

Stack Overflow用户
提问于 2014-09-05 21:02:03
回答 1查看 596关注 0票数 0

我试图让容器自动计算高度,并使用以下代码,但没有运气。

容器名为#featured content

代码语言:javascript
复制
/* <![CDATA[ */

var jqu = jQuery.noConflict();

jqu( function () {  

    /* Cycle */
    jqu( '#featured-content' ).cycle( {
        slideExpr: '.featured-post',
        fx: 'fade',
        speed: 1000,
        cleartypeNoBg: true,
        pager: '#slide-thumbs',
        containerResize: true,
        slideResize:   false,
        width: '100%',
        timeout: 5000,
        prev: '#slider-prev',
        next: '#slider-next',
        pagerAnchorBuilder: function( idx, slide ) { 
            // return selector string for existing anchor 
            return '#slide-thumbs li:eq(' + idx + ') a'; 
        }
    } );
    // call back function to animate the height of the container
    function onAfter(curr, next, opts, fwd) {
        var index = opts.currSlide;
        $('#slider-prev')[index == 0 ? 'hide' : 'show']();
        $('#slider-next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
        //get the height of the current slide
        var $ht = $(this).height();
        //animates the container's height to that of the current slide 
        $(this).parent().animate({ height: $ht });
    }

} );


/* ]]> */
EN

回答 1

Stack Overflow用户

发布于 2014-09-08 04:04:17

回调函数未启动

代码语言:javascript
复制
 after: onAfter,

也可以尝试动画“快速”

$(this).parent().animate({ height: $ht }, "fast");

刚在这里添加了代码http://tny.cz/935e48e2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25686562

复制
相关文章

相似问题

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