简体   繁体   English

ngAnimate max-height无法处理某些元素

[英]ngAnimate max-height not working on certain element

I've implemented ngAnimate into a project to help with animations, but I'm getting really odd behaviour with a certain element. 我已经将ngAnimate实现到一个项目来帮助动画,但我对某个元素的行为非常奇怪。

To add some background, we have a shop with categories and products inside the categories. 为了增加一些背景,我们在类别中有一个包含类别和产品的商店。 I'm doing an ng-repeat with: data-ng-repeat="product in currentProductCategory.Products" and I have data-ng-class="{ 'open': product.ShowDetails == true }" on my root element. 我正在使用: data-ng-repeat="product in currentProductCategory.Products"并且我的根元素上有data-ng-class="{ 'open': product.ShowDetails == true }"

My root element also has an id of product-{{product.Id}}-{{currentProductCategory.Id}} and I have a child element with id product-options-{{product.Id}}-{{currentProductCategory.Id}} which products expected results. 我的根元素也有一个product-{{product.Id}}-{{currentProductCategory.Id}} ID product-{{product.Id}}-{{currentProductCategory.Id}}我有一个带有id product-options-{{product.Id}}-{{currentProductCategory.Id}}的子元素product-options-{{product.Id}}-{{currentProductCategory.Id}}该产品的预期结果。

When clicking a button, I call a function that sets the max-height on the parent element to a desired height, and the animation is handled in the CSS. 单击按钮时,我调用一个函数,将父元素的max-height设置为所需的高度,并在CSS中处理动画。 Here's the function code: 这是功能代码:

var reg = /\d+/g;
var productParentElement = $('#product-' + product.Id + '-' + $scope.currentProductCategory.Id);
var optionsElement = $('#product-options-' + product.Id + '-' + $scope.currentProductCategory.Id);

var productParentPaddingTop = parseInt(productParentElement.css("padding-top").match(reg));
var productParentPaddingBottom = parseInt(productParentElement.css("padding-bottom").match(reg));
var productParentTotalHeight = productParentPaddingTop + productParentPaddingBottom + productParentElement.height() + optionsElement.height();

var optionsElementPaddingTop = parseInt(optionsElement.css("padding-top").match(reg));
var optionsElementPaddingBottom = parseInt(optionsElement.css("padding-bottom").match(reg));
var optionsElementTotalHeight = optionsElementPaddingTop + optionsElementPaddingBottom + optionsElement.height();

var totalHeight = productParentTotalHeight + optionsElementTotalHeight;

if (product.ShowDetails) {
    product.ShowDetails = true;
    productParentElement.css("max-height", totalHeight);
} else {
    product.ShowDetails = false;
    productParentElement.removeAttr('style');
}

And my CSS for the closed and open classes: 我的CSS用于封闭和开放的课程:

Closed: 关闭:

.products-list .product {
    margin-bottom: 20px;
    max-height: 200px;
    overflow: hidden;
    -moz-transition: max-height 2s ease;
    -o-transition: max-height 2s ease;
    -webkit-transition: max-height 2s ease;
    transition: max-height 2s ease;
}

Open: 打开:

.products-list .product.open {
    -moz-transition: max-height 2s ease;
    -o-transition: max-height 2s ease;
    -webkit-transition: max-height 2s ease;
    transition: max-height 2s ease;
    max-height: 200px;
}

The issue is that out of the many products over 4 categories, the same one which is the same product in each category is not animating open. 问题在于,在4个类别的众多产品中,每个类别中相同产品的相同产品并非动画开放。 It animates the close/shrink, but when opening, it just instantly appears open. 它使关闭/缩小动画,但在打开时,它会立即显示为打开状态。

This has been gating on us for a long time now and it's becoming a real issue, any help is greatly appreciated. 这已经给我们很长一段时间了,它已成为一个真正的问题,非常感谢任何帮助。

UPDATE: Now none of the "products" will animate open, but they do animate closed. 更新:现在没有任何“产品”会动画打开,但它们会关闭动画。 Could this be because I'm setting the max-height on the style rather than a class? 这可能是因为我在风格而不是类上设置了最大高度?

Sorry but this might sound like I am pointing out the obvious and I can't see the rest of your code but in your CSS, you have; 抱歉,这可能听起来像我指出了显而易见的,我看不到你的其余代码,但在你的CSS中,你有;

.products-list .product {
    margin-bottom: 20px;
    max-height: 200px;
    overflow: hidden;
    -moz-transition: max-height 2s ease;
    -o-transition: max-height 2s ease;
    -webkit-transition: max-height 2s ease;
    transition: max-height 2s ease;
}

for your closed list which has a 'max-height: 200px' but is also the same in your open list; 对于你的封闭列表,其中包含'max-height:200px',但在打开的列表中也是相同的;

.products-list .product.open {
    -moz-transition: max-height 2s ease;
    -o-transition: max-height 2s ease;
    -webkit-transition: max-height 2s ease;
    transition: max-height 2s ease;
    max-height: 200px;
}

Which also has a max-height of 200px. 其最大高度为200px。 So in this case you're asking it to transition from 200px to 200px. 所以在这种情况下,你要求它从200px过渡到200px。 try changing the height of open classes to be bigger or smaller. 尝试将开放类的高度更改为更大或更小。 Then it will transition. 然后它将过渡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM