javascript - jQuery 在使用动画功能时为 div 添加背景

标签 javascript jquery css html jquery-cycle

我正在使用 jquery 循环插件和 jquery。
当循环的 div 的高度发生变化时,我为 jquery 循环 div 设置动画。下面的 div 根据高度向上或向下。

问题是下面的 div 向下滚动时会得到一个(白色)背景。我希望下面的 div 始终透明。 (在我的示例中,我希望内容 div 始终透明)

这是为循环的 div 设置动画的代码

function onAfter(curr, next, opts, fwd) {
        var index = opts.currSlide;
        $('#prev,#prev2,#prev3,#prev4,#prev5')[index == 0 ? 'hide' : 'show']();
        $('#next,#next2,#next3,#next4,#next5')[index == opts.slideCount - 1 ? 'hide' : 'show']();
        //get the height of the current slide
        var $ht = $(this).height();
        //set the container's height to that of the current slide
        $(this).parent().animate({height: $ht});
    }

    $('.subheader').cycle({after: onAfter});

这很难解释,所以我做了一个 jsfiddle 来展示它:jsFiddle

最佳答案

发生的事情是 overflow: hidden 在被动画化时被添加到 subheader div 中。这样做会使它剪辑文本。

如果您自己制作动画并且设置高度,那应该可以防止问题发生。

或者,我可以使用 !important 样式规则绕过它:Fiddle

.subheader {
    overflow: visible !important;
}

之所以可行,是因为 !important 样式规则比内联样式具有更大的权重(除非内联样式具有 !important,在这种情况下那会赢)。

关于javascript - jQuery 在使用动画功能时为 div 添加背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18630353/

相关文章:

javascript - Webpack:为什么 'style-loader!css-loader!postcss-loader'不处理导入的文件?

javascript - 请推荐一种或多种最佳图表组件,Flash或javascript

javascript - 如何通过单击按钮将 css href 更改为所有 .html 文档?

javascript - 对象文字调用默认属性

javascript - 在 D3.js 中使用数据连接处理元素的删除

javascript - 延迟javascript流程

html - 在不更改响应模板的情况下居中 joomla 菜单

html - 修改表单输入字段

javascript - 我得到 "Expected an conditional expression and instead saw an assignment"即使它有效

javascript - Bootstrap 4 Beta 2 导航栏切换器不工作