I'm trying to write move/scroll text.
So finally I have this.
CODEPEN
There is a problem as you can see. The problem with diplay in the same time two text inside p tags. I want to display the 1st one and then should be show the 2nd one.
I was trying to change values of this
#-moz-keyframes left-one {
0% { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
#-webkit-keyframes left-one {
0% { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
#keyframes left-one {
0% {
-moz-transform: translateX(100%); /* Firefox bug fix */
-webkit-transform: translateX(100%); /* Firefox bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Firefox bug fix */
-webkit-transform: translateX(-100%); /* Firefox bug fix */
transform: translateX(-100%);
}
}
I mean 0% to 50% but it's not good.
How I can solve it?
The whole picture of the animation you want to show is 30s long, not 15s. Each individual animation is 15s on the screen, but the whole animation is 30s if you account for the time of the first animation + the time of the second animation, so they don't overlap.
So change the animation time of both to 30s, and do the first animation in the first 15s (0-50%), and do the second animation in the last 15s (50-100%)
.movetext {
width: 100%;
height: 50px;
overflow: hidden;
position: relative;
background-color: black;
}
.movetext p {
position: absolute;
font-family: Verdana, Arial;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
color: yellow;
font-weight: bold;
font-size: 20px;
transform: translateX(100%);
}
.movetext p:nth-child(1) {
animation: left-one 30s linear infinite;
}
.movetext p:nth-child(2) {
animation: left-two 30s linear infinite;
}
#keyframes left-one {
0% {
transform: translateX(100%);
}
50% {
transform: translateX(-100%);
}
100% {
transform: translateX(-100%);
}
}
#keyframes left-two {
50% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
<div class="container">
<div class="movetext">
<p>Something is here.</p>
<p>But maybe something will be here.</P>
</div>
</div>
Thanks man. It's working very well. :)
I saw there is a little problem on mobile view. The all text is not display properly. It's just cut off. For the other resolutions (>768) everything is good.
So how about this. How I can handle it?
EDIT
I saw the problem. P tag set width of class. I know I can set witdh eg. 700px but I would like to p tag set width of width text.
Related
I made some running text animation animation in CSS same way, as it is in answer here. I tried to implement it like that to avoid any JS manipulation. And everything works fine in Chrome, but text is trembling in Safari.
.marquee {
position: relative;
overflow: hidden;
background: rgb(161, 61, 175);
color: #fff;
}
.marquee span {
display: inline-block;
min-width: 100%; /* this is to prevent shorter text animate to right */
white-space: nowrap;
font-size: 2.5em;
animation: marquee 4s ease-in-out infinite;
}
#keyframes marquee {
0% {
transform: translateX(0);
margin-left: 0;
}
10% {
transform: translateX(0);
margin-left: 0;
}
90% {
transform: translateX(-100%);
margin-left: 100%;
}
100% {
transform: translateX(-100%);
margin-left: 100%;
}
}
<h1 class="marquee">
<span>The only thing that matters now is everything You think of me</span>
</h1>
<p class="marquee">
<span>Beware of short texts!</span>
</p>
I was trying to fix that using only by using CSS, but I still cannot find the solution. Yeah, I can use JS and avoid giving animation to smaller elements. But maybe there is a way to fix this stuff for Safari with CSS only.
My colleague rewritten animation in that way, that it can be handled by Safari. It was obvious to us, that this trembling is caused by using translate + margin, that's why I mentioned it even in title. As you probably know, it is better to avoid margin animations. So, we added wrapper, which have opposite direction animation. Yeah, now we have 2 animations, but they are handled by browsers better, than one with both translation and margin
.marquee {
position: relative;
overflow: hidden;
background: rgb(161, 61, 175);
color: #fff;
}
.marquee-wrapper {
width: 100%;
animation: marquee-wrapper 4s ease-in-out infinite;
}
.marquee span {
display: inline-block;
min-width: 100%; /* this is to prevent shorter text animate to right */
white-space: nowrap;
font-size: 2.5em;
animation: marquee 4s ease-in-out infinite;
}
#keyframes marquee {
0% {
transform: translateX(0);
}
10% {
transform: translateX(0);
}
90% {
transform: translateX(-100%);
}
100% {
transform: translateX(-100%);
}
}
#keyframes marquee-wrapper {
0% {
transform: translateX(0);
}
10% {
transform: translateX(0);
}
90% {
transform: translateX(100%);
}
100% {
transform: translateX(100%);
}
}
<div class="marquee">
<div class="marquee-wrapper">
<span>
The only thing that matters now is everything You think of me
The only thing that matters now is everything You think of me
</span>
</div>
</div>
<br/>
<div class="marquee">
<div class="marquee-wrapper">
<span>Beware of short texts!</span>
</div>
</div>
I would like to add an animated message banner to a website. It works as expected on desktop and tablet view, however, when I go to a certain width in mobile view (roughly 570px), It doesn't display the full message. It takes away the last word of the sentence. The display message should say "Your reality is a matter of your perception". The word perception is being removed.
.animated-message-container {
height: 60px;
background-color:#339a9a;
border-top: 1px solid #000;
}/*Makes changes to position of the text within the purple bar underneath the contact form*/
.animated-message-text {
height: 50px;
overflow: hidden;
position: relative;
}
.animated-message-text h3 {
font-size: 27px;
color: #fff;
position: absolute;
font-family: 'DM Sans', sans-serif;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
padding: 0.17%;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
/* Apply animation to this element */
-moz-animation: example1 20s linear infinite;
-webkit-animation: example1 20s linear infinite;
animation: example1 20s linear infinite;
}
/* Move it (define the animation) */
#-moz-keyframes example1 {
0% { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
#-webkit-keyframes example1 {
0% { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
#keyframes example1 {
0% {
-moz-transform: translateX(100%); /* Firefox bug fix */
-webkit-transform: translateX(100%); /* Firefox bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Firefox bug fix */
-webkit-transform: translateX(-100%); /* Firefox bug fix */
transform: translateX(-100%);
}
}
<div class="animated-message-container">
<div class="animated-message-text">
<h3>"Your reality is a matter of your perception"</h3>
</div>
<!--<p>Get in touch to discuss session availability.</p>-->
</div>
Does anyone know a way to resolve this issue?
Thanks in advance.
Your h3 text is getting wrapped.
Add css
white-space : nowrap;
to prevent this. In this example, I've added it to the h3's css.
.animated-message-container {
height: 60px;
background-color:#339a9a;
border-top: 1px solid #000;
}/*Makes changes to position of the text within the purple bar underneath the contact form*/
.animated-message-text {
height: 50px;
overflow: hidden;
position: relative;
}
.animated-message-text h3 {
white-space: nowrap;
font-size: 27px;
color: #fff;
position: absolute;
font-family: 'DM Sans', sans-serif;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
padding: 0.17%;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
/* Apply animation to this element */
-moz-animation: example1 20s linear infinite;
-webkit-animation: example1 20s linear infinite;
animation: example1 20s linear infinite;
}
/* Move it (define the animation) */
#-moz-keyframes example1 {
0% { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
#-webkit-keyframes example1 {
0% { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
#keyframes example1 {
0% {
-moz-transform: translateX(100%); /* Firefox bug fix */
-webkit-transform: translateX(100%); /* Firefox bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Firefox bug fix */
-webkit-transform: translateX(-100%); /* Firefox bug fix */
transform: translateX(-100%);
}
}
<div class="animated-message-container">
<div class="animated-message-text">
<h3>"Your reality is a matter of your perception"</h3>
</div>
<!--<p>Get in touch to discuss session availability.</p>-->
</div>
I want to scroll the text, word by word, left to right. Just like this page, the word scrolling word by word until the last word. Then it will start again once the last word is hidden.
I am not use <marquee> for iOS because the scrolling text seems like not scrolling smooth like in Android. So, I did some changes in my code.
The result is the scrolling text was not hidden word by word until the last word. The last word not finish scrolling but suddenly it dissapear in a half way. Then it start srcolling again.
try this css code
body {
cursor: url('http://ionicframework.com/img/finger.png'), auto;
}
.scroll-left {
height: 50px;
position: relative;
overflow: hidden;
}
.scroll-left p {
white-space: nowrap !important;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
/* Apply animation to this element */
-moz-animation: scroll-left 20s linear infinite;
-webkit-animation: scroll-left 20s linear infinite;
animation: scroll-left 20s linear infinite;
}
#-moz-keyframes scroll-left {
0% {
-moz-transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%);
}
}
#-webkit-keyframes scroll-left {
0% {
-webkit-transform: translateX(100%);
}
100% {
-webkit-transform: translateX(-100%);
}
}
#keyframes scroll-left {
0% {
-moz-transform: translateX(100%);
/* Browser bug fix */
-webkit-transform: translateX(100%);
/* Browser bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%);
width:165%;
/* Browser bug fix */
-webkit-transform: translateX(-100%);
/* Browser bug fix */
transform: translateX(-100%);
}
}
I found one example from this. It worked fine, but anybody knows how to make scrolling start immediately and after it finish scroll from right to left, immediately it start again. Because right now it wait about 3 second to start scrolling. Thanks.
Below is the CSS:
.example1 {
height: 50px;
overflow: hidden;
position: relative;
}
.example1 h3 {
position: absolute;
width: 100%;
height: 100%;
margin: 0;
line-height: 50px;
text-align: center;
/* Starting position */
-moz-transform:translateX(100%);
-webkit-transform:translateX(100%);
transform:translateX(100%);
/* Apply animation to this element */
-moz-animation: example1 10s linear infinite;
-webkit-animation: example1 10s linear infinite;
animation: example1 10s linear infinite;
}
/* Move it (define the animation) */
#-moz-keyframes example1 {
0% { -moz-transform: translateX(100%); }
100% { -moz-transform: translateX(-100%); }
}
#-webkit-keyframes example1 {
0% { -webkit-transform: translateX(100%); }
100% { -webkit-transform: translateX(-100%); }
}
#keyframes example1 {
0% {
-moz-transform: translateX(100%); /* Firefox bug fix */
-webkit-transform: translateX(100%); /* Firefox bug fix */
transform: translateX(100%);
}
100% {
-moz-transform: translateX(-100%); /* Firefox bug fix */
-webkit-transform: translateX(-100%); /* Firefox bug fix */
transform: translateX(-100%);
}
}
From the example you have shown, all you need to do is add the following styles. .example1 h3 {display: inline-block; width: auto;} and change the animation to about 5s intervals.
The reason it scrolls late is because the width of the h3 is the full width of the screen/div with a centered text so it will be delayed by default.
I'm learning to use CSS to make some animations (start from zero). I saw this cool example on a website. I would like to apply this to my own CSS. However I'm thinking several changes to this
1) Can I change this by a timer. So it can flip automatically after a certain period (say flip every 10 seconds) without any mouse movement.
2) I have two <div> in my HTML file that I want to flip from one to anther. Unfortunately they have got the same class (Something like :widget-inner loadable .widget-size-2x1). So can I use #id (ID selector) instead of class selector in CSS file?
3) I saw other examples using an extra JS file to achieve the flipping animation. Ideally can I just use only CSS to do this?
I have a sample code below which only works partly. It doesn't show the first picture. Please guide on how to make the required changes.
#draggable {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#dashboard {
perspective: 1000;
}
#dashboard {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
.loadable {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
-webkit-animation: mymove 20s infinite; /* Chrome, Safari, Opera */
animation: mymove 20s infinite;
}
#b {
display: block;
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
-webkit-animation: mymove 20s infinite; /* Chrome, Safari, Opera */
animation: mymove 20s infinite;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
40% {transform: rotateY(0deg);}
50% {transform: rotateY(180deg);}
90% {transform: rotateY(180deg);}
100% {transform: rotateY(0deg);}
}
<div id="draggable">
<div id="dashboard" class="shadow">
<div class="widget-inner loadable" id="a">
<img src="http://css3.bradshawenterprises.com/images/Windows%20Logo.jpg"/>
</div>
<div class="widget-inner loadable" id="b">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
Based on the information provided in the question and your comments, it seems like the below snippet is what you require. This would keep flipping infinitely without the need for any mouse interactions to trigger the flip action. When the image is shown, the text will get hidden behind and vice-versa.
The changes that I have made are as follows:
Added transform to rotate the div which contains the image (#a) by -180deg on load because this has to initially look as though it is behind the div that contains the text (#b).
When we flip, we have to flip both #a and #b synchronously but in exactly opposing manner. That is, when #a is made to come forward by using rotateY(0deg), the #b has to go behind and hence at that point in time, it should have rotateY(180deg) and vice-versa. This cannot be achieved using a single animation and hence I have added a separate animation keyframe setting for the front and back sides of the flip.
#draggable {
position: relative;
margin: 10px auto;
width: 450px;
height: 281px;
z-index: 1;
}
#dashboard {
-webkit-perspective: 1000;
perspective: 1000;
}
#dashboard {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
transition: all 1.0s linear;
}
.loadable {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
#a{
-webkit-transform: rotateY(-180deg);
transform: rotateY(-180deg);
-webkit-animation: mymoveback 20s infinite;
animation: mymoveback 20s infinite;
}
#b {
display: block;
box-sizing: border-box;
padding: 10px;
color: white;
text-align: center;
background-color: #aaa;
-webkit-animation: mymove 20s infinite;
animation: mymove 20s infinite;
}
/* Chrome, Safari, Opera */
#-webkit-keyframes mymove {
40% {
-webkit-transform: rotateY(0deg);
}
50% {
-webkit-transform: rotateY(180deg);
}
90% {
-webkit-transform: rotateY(180deg);
}
100% {
-webkit-transform: rotateY(0deg);
}
}
#-webkit-keyframes mymoveback {
40% {
-webkit-transform: rotateY(-180deg);
}
50% {
-webkit-transform: rotateY(0deg);
}
90% {
-webkit-transform: rotateY(0deg);
}
100% {
-webkit-transform: rotateY(-180deg);
}
}
#keyframes mymove {
40% {
transform: rotateY(0deg);
}
50% {
transform: rotateY(180deg);
}
90% {
transform: rotateY(180deg);
}
100% {
transform: rotateY(0deg);
}
}
#keyframes mymoveback {
40% {
transform: rotateY(-180deg);
}
50% {
transform: rotateY(0deg);
}
90% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(-180deg);
}
}
<div id="draggable">
<div id="dashboard" class="shadow">
<div class="widget-inner loadable" id="a">
<img src="http://lorempixel.com/450/281"/>
</div>
<div class="widget-inner loadable" id="b">
<p>This is nice for exposing more information about an image.</p>
<p>Any content can go here.</p>
</div>
</div>
</div>
Flip images to flip on some interval using setInterval method. Demo
$(function() {
setInterval(function() {
$('#f1_card').toggleClass("transformStyle transformRotate");
}, 3000)
})
Sure. you can use pseudo class :hover, and css property
transform: rotateY(180deg); for doing flipping you can control timing using animation and keyframes