CSS3 transition and transform for a marquee effect

Source: Internet
Author: User
This article mainly and we introduce the combination of CSS3 transition transform to achieve a simple example of the results of the light, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

This is a customer needs before, to the demo is to use GIF to realize the marquee, but we can not use GIF, because the text needs to be translated into different languages, so you cannot use the image to achieve, then, write a slightly. Html


<p lantern>  <ul>    <li>1</li>    <li>2</li>    <li>3</li >    <li>4</li>  </ul></p>

Css


* {  margin:0;  padding:0;} [Lantern] {  Overflow:hidden;} UL {  white-space:nowrap;  font-size:0;  Transform:translatex (0);  transition:transform 0s linear;} Li {  width:50vw;  border:1px solid red;  Display:inline-block;  height:30px;  font-size:16px;}

Js


function lantern ($element, speed = ten) {let liwidth = 0;    Let $ul = $element. Find ("ul");      function Run (init = false) {Let $li = $ul. Find ("Li"). First ();      Liwidth = $li. Outerwidth ();        if (!init) {$ul. Append ($li [0].outerhtml);      $li. Remove ();      } $ul [0].style.transitionduration = "0s";      $ul [0].style.transform = "TranslateX (0)";        SetTimeout (function () {$ul [0].style.transitionduration = speed + "s";      $ul [0].style.transform = "TranslateX (-" + Liwidth + "px)";    }, 20);    } run (true);    SetTimeout (() = {SetInterval (run, speed * 1000);  }, 0); } Lantern ($ (' [lantern] '); 
Related Article

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.