Transitions - React-Bootstrap

文章推薦指數: 80 %
投票人數:10人

Bootstrap includes a few general use CSS transitions that can be applied to a number of components. React Bootstrap, bundles them up into a few composable ... MenuGettingstartedLayoutFormsComponentsUtilitiesTransitionsRatio@restart/uiMigratingAboutTransitionsBootstrapincludesafewgeneraluseCSStransitionsthatcanbeapplied toanumberofcomponents.ReactBootstrap,bundlesthemupintoafewcomposable componentsfromreact-transition-group,acommonlyusedanimationwrapperforReact.Encapsulatinganimationsintocomponentshastheaddedbenefitofmakingthemmorebroadlyuseful, aswellasportableforusinginotherlibraries.AllReact-bootstrapcomponentsthatcanbeanimated,supportpluggable components.Collapse#BasicExample#Addacollapsetoggleanimationtoanelementorcomponent.Ifyou'renoticingchoppyanimations,andthecomponentthat'sbeingcollapsedhasnon-zeromarginorpadding,trywrappingthecontentsofyourinsideanodewithnomarginorpadding,likethe

intheexamplebelow.Thiswillallowtheheighttobecomputedproperly,sotheanimationcanproceedsmoothly.functionExample(){ const[open,setOpen]=useState(false); return( <> Animpariaturclichereprehenderit,enimeiusmodhighlifeaccusamus terryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeer laborewesandersoncrednesciuntsapienteeaproident.
> ); } render();functionExample(){const[open,setOpen]=useState(false); return(<>setOpen(!open)}aria-controls="example-collapse-text"aria-expanded={open}>clickAnimpariaturclichereprehenderit,enimeiusmodhighlifeaccusamusterryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeerlaborewesandersoncrednesciuntsapienteeaproident.>);} render();CopyHorizontal#Addacollapsetoggleanimationtoanelementorcomponenttotransitionthewidthinsteadofheight.Ifyou'renoticingchoppyanimations,andthecomponentthat'sbeingcollapsedhasnon-zeromarginorpadding,trywrappingthecontentsofyourinsideanodewithnomarginorpadding,likethe
intheexamplebelow.Thiswillallowtheheighttobecomputedproperly,sotheanimationcanproceedsmoothly.functionExample(){ const[open,setOpen]=useState(false); return( <> Animpariaturclichereprehenderit,enimeiusmodhighlifeaccusamus terryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeer laborewesandersoncrednesciuntsapienteeaproident.
> ); } render();functionExample(){const[open,setOpen]=useState(false); return(<>setOpen(!open)}aria-controls="example-collapse-text"aria-expanded={open}>clickAnimpariaturclichereprehenderit,enimeiusmodhighlifeaccusamusterryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeerlaborewesandersoncrednesciuntsapienteeaproident.>);} render();CopyFade#Addafadeanimationtoachildelementorcomponent.functionExample(){ const[open,setOpen]=useState(false); return( <> Animpariaturclichereprehenderit,enimeiusmodhighlifeaccusamus terryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeer laborewesandersoncrednesciuntsapienteeaproident. > ); } render();functionExample(){const[open,setOpen]=useState(false); return(<>setOpen(!open)}aria-controls="example-fade-text"aria-expanded={open}>ToggletextAnimpariaturclichereprehenderit,enimeiusmodhighlifeaccusamusterryrichardsonadsquid.Nihilanimkeffiyehhelvetica,craftbeerlaborewesandersoncrednesciuntsapienteeaproident.>);} render();CopyAPI#Collapse#viewsourcefileimportCollapsefrom'react-bootstrap/Collapse'CopyimportcodefortheCollapsecomponentNameTypeDefaultDescriptionappearbooleanfalseRuntheexpandanimationwhenthecomponentmounts,ifitisinitially shownchildrenrequiredelementYoumustprovideasingleJSXchildelementtothiscomponentandthatelementcannotbeadimension'height'|'width'|function'height'Thedimensionusedwhencollapsing,orafunctionthatreturnsthe dimensiongetDimensionValuefunctionelement.offsetWidth|element.offsetHeightFunctionthatreturnstheheightorwidthoftheanimatingDOMnode AllowsforprovidingsomecustomlogicforhowmuchtheCollapsecomponent shouldanimateinitsspecifieddimension.Calledwiththecurrent dimensionpropvalueandtheDOMnode.inbooleanfalseShowthecomponent;triggerstheexpandorcollapseanimationmountOnEnterbooleanfalseWaituntilthefirst"enter"transitiontomountthecomponent(addittotheDOM)onEnterfunctionCallbackfiredbeforethecomponentexpandsonEnteredfunctionCallbackfiredafterthecomponenthasexpandedonEnteringfunctionCallbackfiredafterthecomponentstartstoexpandonExitfunctionCallbackfiredbeforethecomponentcollapsesonExitedfunctionCallbackfiredafterthecomponenthascollapsedonExitingfunctionCallbackfiredafterthecomponentstartstocollapserolestringARIAroleofcollapsibleelementtimeoutnumber300Durationofthecollapseanimationinmilliseconds,toensurethat finishingcallbacksarefiredeveniftheoriginalbrowsertransitionend eventsarecanceledunmountOnExitbooleanfalseUnmountthecomponent(removeitfromtheDOM)whenitiscollapsedFade#viewsourcefileimportFadefrom'react-bootstrap/Fade'CopyimportcodefortheFadecomponentNameTypeDefaultDescriptionappearbooleanfalseRunthefadeinanimationwhenthecomponentmounts,ifitisinitially shownchildrenrequiredelementYoumustprovideasingleJSXchildelementtothiscomponentandthatelementcannotbeainbooleanfalseShowthecomponent;triggersthefadeinorfadeoutanimationmountOnEnterbooleanfalseWaituntilthefirst"enter"transitiontomountthecomponent(addittotheDOM)onEnterfunctionCallbackfiredbeforethecomponentfadesinonEnteredfunctionCallbackfiredafterthehascomponentfadedinonEnteringfunctionCallbackfiredafterthecomponentstartstofadeinonExitfunctionCallbackfiredbeforethecomponentfadesoutonExitedfunctionCallbackfiredafterthecomponenthasfadedoutonExitingfunctionCallbackfiredafterthecomponentstartstofadeouttimeoutnumber300Durationofthefadeanimationinmilliseconds,toensurethatfinishing callbacksarefiredeveniftheoriginalbrowsertransitionendeventsare canceledtransitionClassesobject{}Appliesadditionalspecifiedclassesduringthetransition.Takesanobject wherethekeyscorrespondtotheTransitionstatusunmountOnExitbooleanfalseUnmountthecomponent(removeitfromtheDOM)whenitisfadedout



請為這篇文章評分?