Suppress CSS transition when screen size is changed
As suggested in my comment, I added an EventListener for resizing, that checks whether your sub menu is opened or not and removes the class .transition
accordingly. Once you hit toggle again the transition
gets added back. Anyone feel free to comment a smarter solution.
<body>
<div class="container close">
<div class="pane">
<h2>Slideout Header</h2>
</div>
<div class="main">
<button class="toggle">Toggle</button>
</div>
</div>
</body>
* {
box-sizing: border-box;
}
body {
height: 100vh;
}
body .toggle {
position: absolute;
right: 2rem;
top: 2rem;
padding: 0.5rem 1rem;
background: #212121;
color: white;
font-size: 1.2rem;
}
body .pane {
position: fixed;
padding: 1rem 2rem;
background: #ffcccc;
box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.1);
}
body .main {
position: absolute;
background: #00fccf;
padding: 1rem 2rem;
top: 0%;
right: 0%;
left: 0%;
bottom: 0%;
}
body .container {
height: 100%;
width: 100%;
}
@media only screen and (min-width: 1170px) {
body .pane {
top: 0%;
bottom: 0%;
width: 30%;
height: 100%;
}
body .open .pane {
left: 0%;
}
body .open .main {
left: 30%;
}
body .close .pane {
left: -30%;
}
body .close .main {
left: 0%;
}
}
@media only screen and (max-width: 1170px) {
body .pane {
left: 0%;
right: 0%;
width: 100%;
height: 30%;
}
body .open .pane {
bottom: 0%;
}
body .open .main {
bottom: 30%;
}
body .close .pane {
bottom: -30%;
}
body .close .main {
bottom: 0%;
}
}
.transition {
transition: 0.5s all ease;
}
const button = document.querySelector('.toggle');
const pane = document.querySelector('.pane');
const main = document.querySelector('.main');
const container = document.querySelector('.container');
button.addEventListener('click', () => {
container.classList.toggle('open');
container.classList.toggle('close');
pane.classList.add("transition");
main.classList.add("transition");
});
window.addEventListener("resize", function() {
if(container.classList.contains("open")) {
pane.classList.remove("transition");
main.classList.remove("transition");
}
})
How to animate/transition text value change in SwiftUI
So it turns out this is really easy
Text(textValue)
.font(.largeTitle)
.frame(width: 200, height: 200)
.transition(.opacity)
.id("MyTitleComponent" + textValue)
Note the additional id
at the end. SwiftUI uses this to decide if it's dealing with the same view or not when doing a redraw. If the id is different then it assumes the previous view was removed and this one has been added. Because it's adding a new view it applies the specified transition as expected.
NB: It's quite possible that this id should be unique for the entire view tree so you probably want to take care to namespace it accordingly (hence the MyTitleComponent
prefix in the example).
CSS3: Smooth transition between animations change on :hover
I don't think that it can be achieved using the scale transforms.
You can do a trick and change from scale() to translateZ(). When a perspective is applied, the net effect will be also a scale. But the interesting point is than setting perspective to a high value, this scale effect can be made very small. And perspective is an animatable property.
The downside is that we will need to add 2 wrap around layers... but the final result is this. I have kept the original version to compare
@keyframes first-animation {0% { transform: scale(1,1);}50% { transform: scale(0.8,0.8); }100% { transform: scale(1,1); }}
@keyframes second-animation {0% { transform: scale(1,1); }70% { transform: scale(0.7,0.7); }80% { transform: scale(0.9,0.9); }100% { transform: scale(1,1); }}
.sample { background-color: lightblue; animation: first-animation 1.7s ease-in-out infinite;}
.sample:hover {animation: second-animation 1.1s ease-in-out infinite;}
.dim { width: 200px; height: 200px;}
.base1 { perspective: 1000px; transition: perspective 2s ease-out; position: absolute; left: 300px; top: 10px;}.base1:hover { perspective: 9999px;}
.base2 { width: 100%; height: 100%; animation: animation1 1.7s ease-in-out infinite; perspective: 9999px; transition: perspective 2s ease-in;}.base1:hover .base2 { perspective: 1000px;}
.inner { width: 100%; height: 100%; background-color: lightgreen; animation: animation2 1.1s ease-in-out infinite; transform-style: preserve-3d; perspective: 99999px;}
@keyframes animation1 {0% { transform: translateZ(0px);}50% { transform: translateZ(-200px); }100% { transform: translateZ(0px); }}
@keyframes animation2 { 0% { transform: translateZ(0px);} 70% { transform: translateZ(-300px); } 80% { transform: translateZ(-100px); } 100% { transform: translateZ(0px); }}
<div class="sample dim">SAMPLE</div><div class="base1 dim"> <div class="base2"> <div class="inner">DEMO</div> </div></div>
On state change, do animation
okay if i got you correct you want a type of animation like a slow fade In and Out.
In vuejs transitions, state are attached to CSS classes that can be called and modified ass you want it to be. The doc is clearer about it
Vuejs Transitions
for example if you add this in your css section the transition will be a slow fade In and Out:
.fade-enter-active, .fade-leave-active {
transition: opacity .5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
}
SwiftUI - Animate view transition and position change at the same time
You can just change the height as it animates.
Code version #1
This will not fade and appears inside the yellow rectangle.
Code:
struct ContentView: View {
@State var showingSubview = false
var body: some View {
VStack(spacing: 0) {
Button("Show Subview") {
withAnimation(.easeInOut(duration: 2)) {
showingSubview.toggle()
}
}
Text("Subview")
.padding()
.background(Color.green)
.padding(.top)
.frame(height: showingSubview ? nil : 0, alignment: .top)
.clipped()
}
.padding()
.background(Color.yellow)
.offset(x: showingSubview ? 150 : 0, y: 0)
}
}
Result #1
Code version #2
This version will fade out and appear at bottom edge, as your GIF shows.
Code:
struct ContentView: View {
@State var showingSubview = false
var body: some View {
VStack(spacing: 0) {
Button("Show Subview") {
withAnimation(.easeInOut(duration: 2)) {
showingSubview.toggle()
}
}
Text("Subview")
.padding()
.background(Color.green)
.padding(.top)
.frame(height: showingSubview ? nil : 0, alignment: .top)
.padding(.bottom)
.background(Color.yellow)
.clipped()
.opacity(showingSubview ? 1 : 0)
}
.padding([.horizontal, .top])
.background(Color.yellow)
.padding(.bottom)
.offset(x: showingSubview ? 150 : 0, y: 0)
}
}
Result #2
Related Topics
Xcode Doesn't Write Anything to Output Console
Setting Layoutmargins of Uiview Doesn't Work
Authentication with Wkwebview in Swift
Ios/C: Convert "Integer" into Four Character String
Uitableview Pagination - Bottom Refresh to Load New Data in Swift
How to Segue with Data from One Tab to Another Tab Properly
Cannot Invoke Initializer for Type 'Double' with an Argument List of Type '(String)'
Uisearchcontroller Disable Cancel Uibarbuttonitem
Fontawesome Pro and Xamarin.iOS Only One Font Can Be Active
Can the -Objc Flag Be Applied Selectively to Static Libraries
Avaudiosession .Defaulttospeaker Changes Mic Input
How to Get Touchid Information and Compare to a Fingerprint Database
Get Each Line of Text in a Uilabel
Create Custom International Keyboard for Iphone
Constraints for Centering One Button When the Other Is Hidden