JSFiddle
I'm not happy with the current result of the code in the fiddle, I'd like it to be less choppy and just fade in while also sliding in from the bottom but my JQuery skills are not the greatest. Is using CSS as the slide in the best choice? Wasn't able to find any examples of sliding in using JQuery.
Any help much appreciated.
Here's the same code.
<!doctype html>
<html lang="en">
<style>
#keyframes slideInFromBottom {
0% {
transform: translateY(100%);
}
100% {
transform: translateY(0);
}
}
.v1 {
animation: 1s ease-out 0s 1 slideInFromBottom;
}
.v2 {
animation: 1s ease-out 0.2s 1 slideInFromBottom;
}
.v3 {
animation: 1s ease-out 0.4s 1 slideInFromBottom;
}
</style>
<head>
<meta charset="utf-8">
<title>Vista Report</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
</head>
<body>
<div class="row">
<div class="col s12 m4">
<div class="card v1" id="v1">
<div class="card-image">
<img id="preload_v1" src="https://images.unsplash.com/photo-1469461084727-4bfb496cf55a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e7e60237ffbd8c98a087f464f44931c1&auto=format&fit=crop&w=1955&q=80" style="display:none;">
<span class="card-title">Card Title</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.</p>
</div>
</div>
</div>
<div class="col s12 m4">
<div class="card v2" id="v2">
<div class="card-image">
<img id="preload_v2" src="https://images.unsplash.com/photo-1469461084727-4bfb496cf55a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e7e60237ffbd8c98a087f464f44931c1&auto=format&fit=crop&w=1955&q=80" style="display:none;">
<span class="card-title">Card Title</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.</p>
</div>
</div>
</div>
<div class="col s12 m4">
<div class="card v3" id="v3">
<div class="card-image">
<img id="preload_v3" src="https://images.unsplash.com/photo-1469461084727-4bfb496cf55a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e7e60237ffbd8c98a087f464f44931c1&auto=format&fit=crop&w=1955&q=80" style="display:none;">
<span class="card-title">Card Title</span>
</div>
<div class="card-content">
<p>I am a very simple card. I am good at containing small bits of information. I am convenient because I require little markup to use effectively.</p>
</div>
</div>
</div>
</div>
</body>
<script>
$("#v1").ready(function(){
$("#preload_v1").fadeIn(2000);
});
$("#v2").ready(function(){
$("#preload_v2").fadeIn(2000);
});
$("#v3").ready(function(){
$("#preload_v3").fadeIn(2000);
});
</script>
</html>
I removed the jQuery scripts and made it work with css alone.
replaced style="display:none" on img tag with following css
.card{
opacity:0;
}
For fadeIn effect changed opacity from 0 to 1
#keyframes slideInFromBottom {
0% {
transform: translateY(100%);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
To keep the animation in final state added forwards to animation and also updated animation-duration and animation-delay
.v1 {
animation: 1s ease-out 0s 1 slideInFromBottom forwards;
}
.v2 {
animation: 1.2s ease-out 0.2s 1 slideInFromBottom forwards;
}
.v3 {
animation: 1.4s ease-in 0.4s 1 slideInFromBottom forwards;
}
Demo
Related
I'm making a slide sidebar with vuejs and tailwind. It works but feels kind of sluggish. Is there a way to make it smoother ?
working codepen example
.slide-enter-active {
animation: slideIn 1s ease;
}
.slide-leave-active {
animation: slideIn 1s ease reverse;
}
#keyframes slideIn {
0% {max-width: 0%;}
50% {max-width: 50%;}
100% {max-width: 100%}
}
<script src="https://unpkg.com/vue#3"></script>
<button #click="isOpen = !isOpen" class="bg-blue-200 p-5">
<span v-if="isOpen">Open</span>
<span v-else>Close</span>
</button>
<div class="flex flex-row max-w-7xl mx-auto min-h-screen">
<transition name="slide">
<div class="flex flex-col w-64 shadow-xl sm:rounded-lg bg-blue-200" v-if="isOpen">
<div class="min-h-screen">sidebar</div>
</div>
</transition>
<div class="flex w-full min-h-screen bg-red-400">
content
</div>
</div>
You should use transition instead of animation and target the width property :
.slide-enter-active, .slide-leave-active {
transition: width 1s;
}
.slide-enter, .slide-leave-to{
width:0;
}
LIVE DEMO
I've got this great script. It flips the page and reveals new items using a JS code on the backside of this text. But for some reason, on mobile, things go wrong. The h1 and h2 elements disappear...
The issue lies in this css, when I remove the #keyframes it goes away (but then I lose my background):
.background{position:absolute;top:0px;right:0px;bottom:0px;left:0px}
.blue-purple{background-color:#2474c6;background-image:-webkit-linear-gradient(left, #2474c6, #165730);background-image:linear-gradient(to right,#2474c6, #165730);-webkit-animation:fadeInOut 13s ease;-moz-animation:fadeInOut 13s ease;animation:fadeInOut 13s ease;-webkit-animation-fill-mode:forwards;-moz-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;animation-iteration-count:infinite}
.green-blue{background-color:#165730;background-image:-webkit-linear-gradient(left, #165730, #185a9d);background-image:linear-gradient(to right,#165730, #185a9d);-webkit-animation:fadeOutIn 13s ease;-moz-animation:fadeOutIn 13s ease;animation:fadeOutIn 13s ease;-webkit-animation-fill-mode:forwards;-moz-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-iteration-count:infinite;-moz-animation-iteration-count:infinite;animation-iteration-count:infinite}
#-webkit-keyframes "fadeInOut"{0%{opacity:0;}50%{opacity:1;}100%{opacity:0;}}
#-moz-keyframes "fadeInOut"{0%{opacity:0;}50%{opacity:1;}100%{opacity:0;}}
#keyframes "fadeInOut"{0%{opacity:0;}50%{opacity:1;}100%{opacity:0;}}
#-webkit-keyframes "fadeOutIn"{0%{opacity:1;}50%{opacity:0;}100%{opacity:1;}}#-moz-keyframes "fadeOutIn"{0%{opacity:1;}50%{opacity:0;}100%{opacity:1;}}
#keyframes "fadeOutIn"{0%{opacity:1;}50%{opacity:0;}100%{opacity:1;}}
#-webkit-keyframes "fadeIn"{from{opacity:0;}to{opacity:1;}}
#-moz-keyframes "fadeIn"{from{opacity:0;}to{opacity:1;}}
#keyframes "fadeIn"{from{opacity:0;}to{opacity:1;}}#-webkit-keyframes "fadeOut"{from{opacity:1;}to{opacity:0;}}
#-moz-keyframes "fadeOut"{from{opacity:1;}to{opacity:0;}}
#keyframes "fadeOut"{from{opacity:1;}to{opacity:0;}}
and some of the HTML:
<body>
<!----><div class="background blue-purple"></div>
<div class="background green-blue"></div>
<div class="container">
<div class="front">
<div class="inner">
<h1>text here</h1>
</div>
<span>sub text</span>
</div>
<div class="back">
<h2>Text</h2>
<p>Further Text</p>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="assets/js/index.js"></script>
</body>
I am trying to change the speed of a fade effect in Bootstrap. I found this answer using css:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.fade {
opacity: 0;
-webkit-transition: opacity 1.5s linear;
-moz-transition: opacity 1.5s linear;
-ms-transition: opacity 1.5s linear;
-o-transition: opacity 1.5s linear;
transition: opacity 1.5s linear;
}
<div class="btn-group" role="group">
<button class="btn active" data-toggle="tab" href="#one">One</button>
<button class="btn" data-toggle="tab" href="#two">Two</button>
<button class="btn" data-toggle="tab" href="#three">Three</button>
</div>
<div class="tab-content">
<div id="one" class="tab-pane fade in active">This is the One</div>
<div id="two" class="tab-pane fade">This is the Two</div>
<div id="three" class="tab-pane fade">This is the Three</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
...but this only affects the fade-in time. The fade-out stays the same. Any suggestions?
There is no fade-out time, the class that makes the element visible just gets removed.
To make it fade-out, you have to make sure the item doesn't get removed from the dom (HTML document), but rather make it invisible so it can fade.
Here is an example, adjust to your wishes:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.tab-content {
position:relative;
}
.tab-content>.tab-pane {
/* in order to make sure the elements are nicely in position
use position:absolute; */
position:absolute;
top:0;
}
.fade {
opacity: 0;
-webkit-transition: opacity 1.5s linear;
-moz-transition: opacity 1.5s linear;
-ms-transition: opacity 1.5s linear;
-o-transition: opacity 1.5s linear;
transition: opacity 1.5s linear;
}
.tab-content>.tab-pane:not(.in) {
/* display:none; is the default behaviour, make that display:block; */
display:block;
/* make the opacity 0, that is what the transition responds to! */
opacity:0;
}
<div class="btn-group" role="group">
<button class="btn active" data-toggle="tab" href="#one">One</button>
<button class="btn" data-toggle="tab" href="#two">Two</button>
<button class="btn" data-toggle="tab" href="#three">Three</button>
</div>
<div class="tab-content">
<div id="one" class="tab-pane fade in active">This is the One</div>
<div id="two" class="tab-pane fade">This is the Two</div>
<div id="three" class="tab-pane fade">This is the Three</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
The issue is that when an item is not active, it's display property is set to display:none, and therefore is being hidden before any animation can be applied. If you position everything using absolute position to overlap, then you can leave the display as display:block and just change the opacity:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.fade {
opacity: 0;
-webkit-transition: opacity 1.5s linear;
-moz-transition: opacity 1.5s linear;
-ms-transition: opacity 1.5s linear;
-o-transition: opacity 1.5s linear;
transition: opacity 1.5s linear;
}
.tab-content {
position:relative;
}
.tab-content>.tab-pane {
top: 0;
position:absolute;
display:block;
}
.tab-content>.tab-pane:not(.active) {
opacity: 0;
}
<div class="btn-group" role="group">
<button class="btn active" data-toggle="tab" href="#one">One</button>
<button class="btn" data-toggle="tab" href="#two">Two</button>
<button class="btn" data-toggle="tab" href="#three">Three</button>
</div>
<div class="tab-content">
<div id="one" class="tab-pane fade in active">This is the One</div>
<div id="two" class="tab-pane fade">This is the Two</div>
<div id="three" class="tab-pane fade">This is the Three</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
If you simply want to avoid having the fade affect, or need the tabs to appear more quickly remove the fade class.
// Original
<div class="tab-content">
<div id="one" class="tab-pane fade in active">This is the One</div>
<div id="two" class="tab-pane fade">This is the Two</div>
<div id="three" class="tab-pane fade">This is the Three</div>
</div>
// Updated
<div class="tab-content">
<div id="one" class="tab-pane in active">This is the One</div>
<div id="two" class="tab-pane fade">This is the Two</div>
<div id="three" class="tab-pane fade">This is the Three</div>
</div>
The fade class is only applied to the first pane, then when the button is clicked then Jquery removes the active class and fade class and applies it to the corresponding pane.
I am coding a website which needs the full-screen fadein fadeout slider with content and next previous navigation . So I found this.
But the main problem is that I need this effect to fadein fadeout.
You can use bootstrap-carousel
http://getbootstrap.com/javascript/#carousel
For auto-gen help
http://www.bootply.com/64693
Here I'm giving one work-around for you with this fiddle http://jsfiddle.net/fj75wqwc/
The same is below:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<style>
.carousel.carousel-fade .item {
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
opacity: 0;
}
.carousel.carousel-fade .active.item {
opacity: 1;
}
.carousel.carousel-fade .active.left,
.carousel.carousel-fade .active.right {
left: 0;
z-index: 2;
opacity: 0;
filter: alpha(opacity=0);
}
.carousel.carousel-fade .next,
.carousel.carousel-fade .prev {
left: 0;
z-index: 1;
}
.carousel.carousel-fade .carousel-control {
z-index: 3;
}
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="page-header text-center">
<h1>Bootstrap Carousel with fade effect</h1>
</div>
<div class="span6 offset3">
<div id="carousel_fade" class="carousel slide carousel-fade">
<div class="carousel-inner">
<div class="item active">
<!-- you can add any content here-->
<img src="http://placehold.it/600x400&text=Fade+effect-Page-1">
</div>
<div class="item ">
<!-- you can add any content here-->
<img src="http://placehold.it/600x400&text=Fade+effect-Page-2">
</div>
</div>
<a class="carousel-control left btn-control " href="#carousel_fade" data-slide="prev">‹</a>
<a class="carousel-control right btn-control" href="#carousel_fade" data-slide="next">›</a>
</div>
</div>
</div>
</div>
<script>
$(function() {
$('.carousel').carousel({
interval: 7000
})
})
</script>
</body>
</html>
I've been trying to understand why my carousel won't fade between transitions. It cycles as expected, but don't seem to apply the transition effect to make one panel fade in to the next.
Here's what I have so far:
/* Javascript */
function cycle() {
var active = $('.carousel .item.active');
var panels = $('.carousel .item');
var pos = panels.index(active);
var next = panels.eq((pos >= 5) ? 0 : ++pos);
next.addClass('active');
active.removeClass('active');
}
var interval = setInterval(cycle, 2000);
/* CSS */
.carousel-inner {
position: relative;
width: 100%;
overflow: hidden;
}
.carousel .item {
-webkit-transition: opacity 0.6s ease-in-out;
-moz-transition: opacity 0.6s ease-in-out;
-o-transition: opacity 0.6s ease-in-out;
transition: opacity 0.6s ease-in-out;
opacity: 0;
}
.carousel .item.active {
opacity: 1;
}
/* HTML */
<div id="id_landing_carousel" class="carousel slide">
<div class="carousel-inner">
<div class="item" data-nav-button="nav-home">
<img src="/media/carousel/home.png">
<div class="carousel-caption">
<h4><p>Welcome</p></h4>
</div>
</div>
<div class="item" data-nav-button="nav-residential">
<img src="/media/carousel/residential.jpg">
<div class="carousel-caption">
<h4><p>Residential</p></h4>
</div>
</div>
<div class="item" data-nav-button="nav-commercial">
<img src="/media/carousel/commercial.jpg">
<div class="carousel-caption">
<h4><p>Commercial</p></h4>
</div>
</div>
<div class="item" data-nav-button="nav-service">
<img src="/media/carousel/service.jpg">
<div class="carousel-caption">
<h4><p>Service</p></h4>
</div>
</div>
<div class="item active" data-nav-button="nav-blog">
<img src="/media/carousel/blog.jpg">
<div class="carousel-caption">
<h4><p>Blog</p></h4>
</div>
</div>
<div class="item" data-nav-button="nav-contact">
<img src="/media/carousel/contact.jpg">
<div class="carousel-caption">
<h4><p>Contact us</p></h4>
</div>
</div>
</div>
</div>
If anyone has any insight in to what I"m doing wrong, I'd very much appreciate it.
Damn. Nevermind. Solved it myself. Another style was setting the carousel's div element to display: none when it wasn't active.