I have several blocks of content. I slide one off to the side, then remove it. Once that is done, I want the blocks below it to slide up and take its place.
JSFiddle Example
HTML
<div id="container">
<div id="elem1" class="item one">
Element 1
</div>
<div id="elem2" class="item two">
Element 2
</div>
<div id="elem3" class="item three">
Element 3
</div>
</div>
CSS
.one {
background-color: red;
}
.two {
background-color: blue;
}
.three {
background-color: green;
}
.item {
height: 150px;
width: 200px;
margin-bottom: 20px;
}
.closed {
-webkit-transition: all .75s ease;
-moz-transition: all .75s ease;
-o-transition: all .75s ease;
transition: all .75s ease;
background-color: yellow;
margin-left: 200px;
opacity: 0;
}
Javascript/JQuery
$('.item').on('click', function(){
$(this)
.addClass('closed')
.on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', function(){
$(this).remove();
});
});
What transition can I uses so that if I click the red block, once it is removed the blue and green blocks will slide into place?
Working Fiddle
Give a try to this;
$(this).height(0).css({'margin':'0'});
or Probably this;
$(this).css({'margin':'0','height':'0'});
good luck!
You can animate with height and margin equal to 0
$('.item').on('click', function(){
var obj = $(this);
$(this)
.addClass('closed')
.on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', function(){
obj.animate({ height: 0, margin : 0 }, 0);
});
});
Here is the fiddle link DEMO
You can use .animate() with time and adjust top or margin-top to move the element out of view. Once out you can remove the element and reset the top / margin-top to its original value.
Related
The problem I'm facing is:
I have a animated text which goes from right to left, this text change depending on the languague set, what is causing that the total width of the text changes too.
In this picture, the effect I want is working fine, because some properties are fixed.
Now, when I change for a longer text the problem cames up.
So, this is what I have now:
And this is what I'd like to have:
Here is the code I'm using:
ReactJS Side:
constructor(props) {
super(props);
this.state = {
checked: false
}
}
componentDidMount() {
window.addEventListener('scroll', () => {
if (event.srcElement.body.scrollTop >= 1400) {
this.setState({ checked: true });
}
});
}
render() {
return (
<div>
... stuff
<span style={{ fontSize: "40px", color: this.state.theme.COLOR_3 }}>
<input type="checkbox" id="Resume-chk" style={{ display: "none" }} checked={this.state.checked} />
<b id="Resume-title">{this.state.languageSet.RESUME}</b>
</span>
... more stuff
<div>
);
}
CSS Side:
//This is the text
#Resume-title {
display: inline-block;
-webkit-transition: color 200ms ease-in;
-moz-transition: color 200ms ease-in;
transition: color 200ms ease-in;
-webkit-transition: right 500ms ease-in;
-moz-transition: right 500ms ease-in;
transition: right 500ms ease-in;
position: relative;
right: -40.5%;
}
//This is the text when the checkbox is checked
#Resume-chk:checked ~ #Resume-title {
right: 40.5%;
}
So, the question is: How to fix it? Or maybe there is some concept I'm missing and it is a little bit more than just fixing a bug.
Also I'm not sure if doing things like right: -40.5%; and right: 40.5%; is a good practice, but I cant find a way to animate property like float or align.
Of course, if there is a way to fix it, but also there is a way to do it even better, It is also welcome!!!
EDITED: here the fiddle containing the whole html section, copied from dev console
You need a combination of positioning with right and a transform.
This is an usual idea for centering an element, adapted to your request:
.container {
width: 300px;
background-color: lime;
margin: 10px;
position: relative;
}
.item {
display: inline-block;
position: relative;
right: -100%;
transform: translateX(-100%);
transition: right 1s, transform 1s;
}
.container:hover .item {
right: 0%;
transform: translateX(0%);
}
<div class="container">
<div class="item">Item</div>
</div>
<div class="container">
<div class="item">Item long</div>
</div><div class="container">
<div class="item">Item longer longer</div>
</div>
Using transform on two elements works fine in IE and Firefox but somehow "stutters" in Chrome.
I've captured the different behaviours with some gifs:
Firefox
IE
Chrome (notice how the right border "jumps" around")
Example on jsfiddle
Is it possible to fix this behaviour in Chrome? I couldn't find anything when I searched.
Thanks for your help in advance :)
Here is some exemplary code.
HTML:
<div class="outer">
<div class="menu">
asdf
</div>
<div class="content">
<button id="trigger">toggle menu</button>
</div>
</div>
CSS:
.outer > div {
transition: transform 500ms ease, margin-right 500ms ease;
}
.menu {
background-color: #1d1f20;
top: 0;
left: -200px;
width: 200px;
position: fixed;
transform: translate(200px,0);
}
.content {
transform: translate(200px, 0px);
margin-right: 200px;
background: green;
}
JS:
var current = '200px';
$('#trigger').on('click', function() {
current = current === '200px' ? '0' : '200px';
$('.menu').css({transform: 'translate('+current+', 0)'});
$('.content').css({transform: 'translate('+current+', 0)', marginRight: current === '200px' ? '200px' : '0'});
});
I'm using
jsfiddle.net/ts4dk6hp/
and wondering if I can
a) have the content open by default
b) have a smooth css transition to open (with no javascript)
HTML
<div id="show">
Open
<div id="content">
Close
<br>some text...
</div>
</div>
CSS
#content {
display: none;
}
#show:target #content {
display: block;
}
#show:target #open {
display: none;
}
Any help would be great thanks!
First, I suggest you use javascript instead of just css. 2nd, I want to you to remember that css animations are only supported by newer browsers.
I have updated your jsfiddle, hopefully it will be helpful for you.
HTML
<div id="show">
Open
<div id="content">
<br>some text...
<br> Mur text, duh...
<br> Lorem
<br> Ipsum
<br> Watchama sayin'?
<br> Have fun!
</div>
CSS
#content {
transition: opacity 1s ease-in, height 500ms ease-out;
opacity: 0;
height: 200px;
width: 200px;
background: gray;
}
JS
var open = true;
$('#openclose').click(function() {
if (!open) {
open = true;
$(this).text('Close');
$('#content').css({
opacity: 1,
height: '200px',
overflow: 'hidden',
});
$('#content').one('transitionend', function() {
$(this).css('overflow', 'auto');
});
} else {
open = false;
$(this).text('Open');
$('#content').css({
opacity: 0,
height: '0px',
overflow: 'hidden',
});
$('#content').one('transitionend', function() {
$(this).css('overflow', 'auto');
});
}
});
http://jsfiddle.net/MashedPotatoes/ts4dk6hp/13/
To expand on humble.rumble.6x3's comment, you cannot do the first OR the second of your requirements without JavaScript. The main reason being that CSS is designed to style the content, not perform animations and interact with events (with exceptions).
Following way you can do using css:
1.) content open by default And smooth css transition to open (with no javascript).
#open {
display: none;
}
#show:target #content {
opacity: 0;
}
#show:target #close {
display: none;
}
#show:target #open {
display: block;
}
#content{
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#show{
display:table;
}
<div id="show">
<a href="#show" id="close" >Close</a>
<a href="#hide" id="open" >Open</a>
<div id="content">
<br>some text...
</div>
</div>
Hope it helps.
I have a page that creates a pop-up notification whenever a message is broadcasted from another user. The pop-up is basically a div that holds content from the sent message with a button that allows you to close it.
Now I've researched a million ways to create transitions that extend properties using pseudo classes but my question is this: Is it possible to create a banner at the top of the page that slides down with the message when it's sent by another using pure CSS3 / transition mixins?
My thought was to transition the max-height property but obviously it isn't working. I'm assuming because there is no height to begin with.
CSS:
.banner-messages {
> div {
background-color: #74bce7;
color: #fff;
top: 0;
left: 0;
padding: 20px 30px;
position: relative;
line-height: 100%;
width: 100%;
max-height: 0;
z-index: 1000;
overflow-y: hidden;
#include drop-down;
}
}
#mixin drop-down {
max-height: 200px;
-webkit-transition: all 1.5s linear;
-moz-transition: all 1.5s linear;
-o-transition: all 1.5s linear;
transition: all 1.5s linear;
}
HTML:
<div id="test" class="banner-messages" data-bind="foreach: messages">
<div class="banner-message">
<img data-bind="imgSrc: 'radio.svg'">
<div class="banner-body">
<p class="banner-title">{{title}}</p>
<pre>{{message}}</pre>
</div>
<span class="exit-dialout-panel icon icon-closes" data-bind="visible: dismissable, click: $parent.dismissMessage.bind($parent, $data)"></span>
</div>
Try adding a class with the css binding that applies transform: translateY:
var Viewmodel = function Viewmodel() {
var that = this;
this.messages = ko.observableArray([]);
this.removeMessages = function removeMessages() {
that.messages.removeAll();
};
this.addMessage = function addMessage() {
that.messages.push("A new message came in");
};
};
ko.applyBindings( new Viewmodel() );
header {
transition: transform 0.3s;
transform: translateY(-110%);
background-color: lightblue;
padding: 2rem;
font-family: sans-serif;
}
header.active {
transform: translateY(0);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<main>
<header data-bind="css: { active: messages().length > 0 }">
<ul data-bind="foreach: messages">
<li data-bind="text: $data"></li>
</ul>
<button data-bind="click: removeMessages">mark all as read</button>
</header>
</main>
<button data-bind="click: addMessage">Add message</button>
I have a page with an element that has an animation on hide/show. The page loads when the element is not shown but still, when the page loads it shows the hide animation.
I've even tried to change the condition to ng-show="false" and still I see the hide animation when page loads.I've understood that there was an old problem with angularjs about this but I'm using 1.2.2.
HTML:
<div class="c_redDiv" ng-show="state == true">
<div ...>
<button ...>
<div ... />
</button>
<button ...>
<div ... />
</button>
</div>
</div>
CSS:
.c_redDiv.ng-hide-add, .c_redDiv.ng-hide-remove {
-webkit-transition: all linear 0.5s;
-moz-transition: all linear 0.5s;
-o-transition: all linear 0.5s;
transition: all linear 0.5s;
display: block !important;
}
.c_redDiv.ng-hide-add.ng-hide-add-active,
.c_redDiv.ng-hide-remove {
opacity: 1;
top: -50px;
}
.c_redDiv.ng-hide-add,
.c_redDiv.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
top: 0px
}
you should add to your css:
.c_redDiv{
display:none;
}
.c_redDiv.ng-show{
display:block;
}
I was unable to find a way to avoid the initial animation triggering when ng-hide or ng-show is used, but was able to get it working with ng-if.
HTML:
<div class="c_redDiv" ng-if="state == true">
...
</div>
SASS:
.c_redDiv {
overflow: hidden;
transition: max-height 0.35s ease;
&.ng-leave, &.ng-enter.ng-enter-active {
max-height: 300px;
}
&.ng-leave.ng-leave-active, &.ng-enter {
max-height: 0;
}
}