css - CSS3 Marquee Effect -


i'm creating marquee effect css3 animation. here codes.

html tag:

<div id="caption">     quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog. </div> 

css:

#caption {     position: fixed;     bottom: 0;     left: 0;     font-size: 20px;     line-height: 30px;     height:30px;     width: 100%;     white-space: nowrap;     -moz-animation:  caption 50s linear 0s infinite;     -webkit-animation:  caption 50s linear 0s infinite; } @-moz-keyframes caption { 0% { margin-left:120%; } 100% { margin-left:-4200px; }  } @-webkit-keyframes caption { 0% { margin-left:120%; } 100% { margin-left:-4200px; }  } 

now can basic marquee effect, codes not wise enough.

i wonder if there way avoid using specific values margin-left:-4200px;, can adapt text in length.

also, doesn't perform smoothly in firefox , safari, performs in chrome.

here similar demo: http://jsfiddle.net/jonathansampson/xxuxd/, uses text-indent still specific values.

any advice appreciated.

fred

with small change of markup, here's approach (i've inserted span inside paragraph):

example fiddle: http://jsfiddle.net/may5a/1/ (borders included debug purpose, tested on firefox , chrome)


markup

<p class="microsoft marquee"><span>windows 8 , ...</span></p> 

css

.marquee {     width: 450px;     margin: 0 auto;     white-space: nowrap;     overflow: hidden;     box-sizing: border-box; }  .marquee span {     display: inline-block;     padding-left: 100%;  /* show marquee outside paragraph */     animation: marquee 15s linear infinite; }  .marquee span:hover {     animation-play-state: paused }  /* make move */ @keyframes marquee {     0%   { transform: translate(0, 0); }     100% { transform: translate(-100%, 0); } } 

no hardcoded values — dependent on paragraph width — have been inserted

the animation applies css3 transform property (use prefixes needed) performs well.

if need insert delay once @ beginning set animation-delay. if need instead insert small delay @ every loop try play higher padding-left (e.g. 150%)


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -