Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="wrapper">
  <div class="t1">
    <marquee>[html marquee] Hello! What time is it now?</marquee>
  </div>
  <div class="t2">
    <p>[css marquee] It's 9:30. If I have very long text..? It's 9:30. If I have very long text..?</p>
  </div>
  <div class="t3">
    <p id="marp">[JS marquee] Javascript keeps me moving :) (using requestAnimationFrame)</p>
  </div>
  <div class="t4">
    <p id="marp2">[JS marquee] Javascript keeps me moving :) (using setTimeout)</p>
  </div>
  
</div>

<div class="wrapper2">
  <div class="t5">
    <p>[CSS marquee] I move up and down.</p>
  </div>
</div>

              
            
!

CSS

              
                * {
  font-family: sans-serif;
}

.wrapper {
  width: 300px;
  margin: auto;
  border: solid 1px tomato;
}

.t2 {
  /* for css marquee */
  overflow: hidden;
}

.t2 > p {
  animation: 7s linear 0s  infinite marquee;
/*   border: solid 1px black; */
  white-space: nowrap;
  width: fit-content;
}

@keyframes marquee {
  from {
    transform: translate(50%);
  }
  to { 
    transform: translate(-100%); 
  }
}

.t3, .t4 {
  overflow: hidden;
}

.t3 > p {
  white-space: nowrap;
  width: fit-content;
}

.t4 > p {
  white-space: nowrap;
  width: fit-content;
}


.wrapper2 {
  width: 250px;
  height: 300px;
  border: solid 1px greenyellow;
  margin: 12px auto;
}

.t5 {
  overflow: scroll;
  height: 100px;
  border: solid 1px grey;
}

.t5 > p {
  margin: 0;
  white-space: nowrap;
  width: fit-content;
  height: 100%;
  animation: 3s linear 0s  infinite marqueeUD;
}

@keyframes marqueeUD {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(100%);
  }
}

              
            
!

JS

              
                // requestAnimationFrame version
const pelm = document.getElementById("marp");
const parent_pelm = document.getElementsByClassName("t3")[0];

// この2つはt3,t4で共通
const DURATION = 5;  //sec
const PLAY_COUNT = "inf";

let startTS = null;
let play_count = 1;
function marqueef(ts) {
  let needNextReq = false;
  if(startTS == null) startTS = ts;
  const pw = pelm.clientWidth;
  const ppw = parent_pelm.clientWidth;
  const progress = (ts - startTS) / (DURATION * 1000);
  if(progress > 1) {
    if(PLAY_COUNT === "inf" || PLAY_COUNT > play_count) {
      startTS = null;
      play_count++;
      needNextReq = true;
    }
  } else {
    needNextReq = true;
  }
  
  const newpos = (pw + ppw) * (1 - progress) - pw;
  pelm.style.transform = "translate(" + newpos + "px"+")";
  
  if(needNextReq) {
    requestAnimationFrame(marqueef);
  }
}

requestAnimationFrame(marqueef);


// setTimeout version
const t4_pelm = document.getElementById("marp2");
const t4_parent_pelm = document.getElementsByClassName("t4")[0];

// 再描画間隔
const t4_INTERVAL = 1000/15;  //ms

let t4_play_count = 1;
let t4_frame_count = 0;  // 1ループ内での呼び出し回数
function t4_marqueef() {
  let needNextRender = false;
  const pw = t4_pelm.clientWidth;
  const ppw = t4_parent_pelm.clientWidth;
  const progress = (t4_frame_count * t4_INTERVAL) / (DURATION * 1000);
  if(progress > 1) {
    if(PLAY_COUNT === "inf" || PLAY_COUNT > t4_play_count) {
      t4_play_count++;
      t4_frame_count = 0;
      needNextRender = true;
    }
  } else {
    needNextRender = true;
    t4_frame_count++;
  }

  const newpos = (pw + ppw) * (1 - progress) - pw;
  t4_pelm.style.transform = "translate(" + newpos + "px"+")";
  if(needNextRender) {
    setTimeout(t4_marqueef, t4_INTERVAL);
  }
}

setTimeout(t4_marqueef, 0);

              
            
!
999px

Console