CSS3 Transition and animation implement Merry

Source: Internet
Author: User

This period of time is doing a app,h5 development. There are announcements on the page that appear in the form of merry.

At the beginning of the direct use of the marquee tag, later found in the iOS client, the merry move is not smooth enough, there is a jitter phenomenon.

For obsessive-compulsive disorder I was unbearable, and then use JS to write, found that the Andriod and iOS client merry move is not smooth, will jitter.

Later thought can use CSS3 transition and animation to write, share the code!

Transition notation

<! DOCTYPE html>body{padding:0; margin:0;} #demo {width:100%; Height:50px;background: #eee;p osition:fixed;} #demo>#spa {Word- Break: keep-All;white-Space:nowrap;position:absolute;left:100%; font-Size:30px;line-height:50px;}</style>varSpa = document.getElementById ("Spa"); varSpaw =Spa.offsetwidth; varBodyw =Document.body.clientWidth; varW = 0-(spaw+Bodyw); Spa.style.transform= ' Translate (' + W + ' px, 0px) '; Spa.style.transition= ' Transform 5s linear '; Window.setinterval (function() {Spa.style.transform= ' translate (0px, 0px) '; Spa.style.transition= ' transform 0s linear '; Window.settimeout (function() {Spa.style.transform= ' Translate (' + W + ' px, 0px) '; Spa.style.transition= ' Transform 5s linear '; },100)     },5000)</script>

Note that on the iphone4s, the Transition property suggests separate write, direct write transition set four properties, Ihone4s Browser is not recognized.

Animation notation

<! DOCTYPE html>#demo {width:100%; Height:50px;background: #eee;p osition:fixed;} #demo>Span{word- Break: keep-All;white-Space:nowrap;position:absolute;left:100%; font-Size:30px;line-height:50px;} #demo>. a{-webkit-Animation:demo 5s Infinite;-webkit-animation-timing-function: linear;}</style><style id= ' asty ' ></style>varSpa = document.getElementById ("Spa"); varwidth = 0-(Spa.offsetwidth); varstyle = document.getElementById ("Asty"); Style.innerhtml= ' @-webkit-keyframes demo{from {left:100%;} To {left: ' +width+ ' px;} '; Spa.classname= ' A ';</script>

CSS3 Transition and animation implement Merry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.