You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					40 lines
				
				1.1 KiB
			
		
		
			
		
	
	
					40 lines
				
				1.1 KiB
			| 
								 
											6 months ago
										 
									 | 
							
								import { getRect } from '../common/utils';
							 | 
						||
| 
								 | 
							
								function useAnimation(context, expanded, mounted, height) {
							 | 
						||
| 
								 | 
							
								    const animation = wx.createAnimation({
							 | 
						||
| 
								 | 
							
								        duration: 0,
							 | 
						||
| 
								 | 
							
								        timingFunction: 'ease-in-out',
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								    if (expanded) {
							 | 
						||
| 
								 | 
							
								        if (height === 0) {
							 | 
						||
| 
								 | 
							
								            animation.height('auto').top(1).step();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        else {
							 | 
						||
| 
								 | 
							
								            animation
							 | 
						||
| 
								 | 
							
								                .height(height)
							 | 
						||
| 
								 | 
							
								                .top(1)
							 | 
						||
| 
								 | 
							
								                .step({
							 | 
						||
| 
								 | 
							
								                duration: mounted ? 300 : 1,
							 | 
						||
| 
								 | 
							
								            })
							 | 
						||
| 
								 | 
							
								                .height('auto')
							 | 
						||
| 
								 | 
							
								                .step();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        context.setData({
							 | 
						||
| 
								 | 
							
								            animation: animation.export(),
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								        return;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    animation.height(height).top(0).step({ duration: 1 }).height(0).step({
							 | 
						||
| 
								 | 
							
								        duration: 300,
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								    context.setData({
							 | 
						||
| 
								 | 
							
								        animation: animation.export(),
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								export function setContentAnimate(context, expanded, mounted) {
							 | 
						||
| 
								 | 
							
								    getRect(context, '.van-collapse-item__content')
							 | 
						||
| 
								 | 
							
								        .then((rect) => rect.height)
							 | 
						||
| 
								 | 
							
								        .then((height) => {
							 | 
						||
| 
								 | 
							
								        useAnimation(context, expanded, mounted, height);
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								}
							 |