Animerad expandering används för att visa och dölja innehåll via en vertikal animering.
Exempel med radioknappar som fäller ut ytterligare fält (även nästlade understödjs).
Visa kod
<template >
<f-fieldset name ="more-questions" >
<template #label > Vill du svar på mer frågor? </template >
<f-radio-field v-model ="moreQuestions" :value ="true" > Ja tack </f-radio-field >
<i-animate-expand :expanded ="moreQuestions" >
<f-fieldset class ="indent" name ="are-you-sure" >
<template #label > Är du säker? </template >
<f-radio-field v-model ="areYouSure" :value ="true" > Ja, visa mer </f-radio-field >
<i-animate-expand :expanded ="areYouSure" >
<f-text-field v-validation.maxLength class ="indent" >
Vad tyckte du?
</f-text-field >
</i-animate-expand >
<f-radio-field v-model ="areYouSure" :value ="false" > Nej tack </f-radio-field >
</f-fieldset >
</i-animate-expand >
<f-radio-field v-model ="moreQuestions" :value ="false" > Nej tack </f-radio-field >
</f-fieldset >
</template >
<script >
import { defineComponent } from "vue" ;
import { IAnimateExpand , FFieldset , FRadioField , FTextField } from "@fkui/vue" ;
export default defineComponent ({
namne : "IAnimateExpandRadioGroup" ,
components : { IAnimateExpand , FFieldset , FRadioField , FTextField },
data ( ) {
return {
moreQuestions : "" ,
areYouSure : "" ,
};
},
});
</script >
Visa kod
<template >
<div >
<button type ="button" @click ="isExpanded = !isExpanded" > Öppna/stäng animering</button >
<input v-model ="isAnimated" type ="checkbox" /> Animera
<input v-model ="hasOpacity" type ="checkbox" /> Opacitet
<input v-model ="useVShow" type ="checkbox" /> Use v-show instead of v-if
<select v-model ="style" >
<option value ="height: 200px; background: hotpink" > 200px höjd</option >
<option value ="height: 600px; background: cyan" > 600px höjd</option >
<option value ="height: 1200px; background: yellow" > 1200px höjd</option >
</select >
<pre > Callback: {{ callbackInfo }}</pre >
<pre > Finns innehålls-div i DOM: {{ contentDivInDOM }}</pre >
<i-animate-expand
:expanded ="isExpanded"
:opacity ="hasOpacity"
:animate ="isAnimated"
:use-v-show ="useVShow"
:before-animation ="beforeAnimationCallback"
:after-animation ="afterAnimationCallback"
>
<div ref ="content-div" :style ="style" > Ett animerat innehåll kan visas här.</div >
</i-animate-expand >
</div >
</template >
<script >
import { defineComponent } from "vue" ;
import { IAnimateExpand } from "@fkui/vue" ;
export default defineComponent ({
namne : "IAnimateExpandRecommended" ,
components : { IAnimateExpand },
data ( ) {
return {
isExpanded : false ,
isAnimated : true ,
useVShow : false ,
hasOpacity : true ,
style : "height: 200px; background: hotpink" ,
callbackInfo : "" ,
contentDivInDOM : false ,
};
},
methods : {
beforeAnimationCallback ( ) {
console .log ("Before animation callback" );
this .callbackInfo = "Before animation callback" ;
},
afterAnimationCallback ( ) {
console .log ("After animation callback" );
this .callbackInfo = "After animation callback" ;
setTimeout (() => {
this .contentDivInDOM = this .$el .contains (this .$refs ["content-div" ]);
});
},
},
});
</script >
<style >
input ,
select {
margin-left : 20px ;
}
</style >
Exempel på hur två animeringar kan samverka.
Visa kod
<template >
<div >
<button type ="button" @click ="toggle = !toggle" > Toggle</button >
<input v-model ="opacity" type ="checkbox" /> Toning
<i-animate-expand :opacity ="opacity" :expanded ="toggle" >
<div style ="background-color: yellow; height: 200px; position: relative" > </div >
</i-animate-expand >
<i-animate-expand :opacity ="opacity" :expanded ="!toggle" >
<div style ="background-color: hotpink; height: 300px; position: relative" > </div >
</i-animate-expand >
</div >
</template >
<script >
import { defineComponent } from "vue" ;
import { IAnimateExpand } from "@fkui/vue" ;
export default defineComponent ({
namne : "IAnimateExpandToggleTwo" ,
components : { IAnimateExpand },
data ( ) {
return {
toggle : false ,
opacity : false ,
};
},
});
</script >
Props Name Description Type Required Default animate
Perform animation or not
boolean
false
true
useVShow
Use v-show instead of v-if when hiding content.
boolean
false
false
expanded
Toggle expanded/collapsed state
string|number|boolean
false
true
opacity
‐
boolean
false
true
beforeAnimation
Optional callback for performing actions before animation.
Callback will await Promise.
AnimationCallback
false
function() {
return () => {
/* do nothing */
};
}
afterAnimation
Optional callback for performing actions after animation.
Callback will await Promise.
AnimationCallback
false
function() {
return () => {
/* do nothing */
};
}
Slots Name Description Bindings default
Slot used for content shown when component is expanded
‐