Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                #main.main
%button#play PLAY
%button#pause PAUSE
%button#rewind REWIND
%button#reset RESET
#settings
  %select{id: 'direction'}
    %option{value: 'rl', selected: 'selected'} Right to left
    %option{value: 'lr'} Left to right
    %option{value: 'tb'} Top to bottom
    %option{value: 'bt'} Bottom to top
  %label{for: 'font-size'} Font-size:
  %input#font-size{value: 24} px
  %label{for: 'top-pad'} Top pad:
  %input#top-pad{value: 5} px
  %label{for: 'bottom-pad'} Bottom pad:
  %input#bottom-pad{value: 8} px
  %label{for: 'repeats'} Repeats:
  %input#repeats{value: 3}
  %label{for: 'space'} Pixels between repeats:
  %input#space{value: 120}
  %label{for: 'speed'} Seconds to read:
  %input#speed{value: 10}
#container
  %textarea{cols: 100, rows: 9}
    :preserve
      College football player who helps kids in need surprised with scholarship. The Minnesota Gophers' backup kicker was given a full scholarship for his final season.
              
            
!

CSS

              
                @font-face
  font-family: 'alphaEcho'
  src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.woff') format('woff')
  src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/alpha_echo-webfont.ttf') format('truetype')
  font-weight: normal
  font-style: normal
body
  background: white
.main
  background: black
  font-family: 'alphaEcho'
  width: 720px
  height: 300px
  font-size: 18px
  border: 1px solid #efefef
  padding: 0
  margin: 5px 0
  position: relative
  display: flex
  flex-flow: column
  justify-content: center
  align-items: center
  text-rendering: auto
  box-sizing: border-box
  overflow: hidden
input
  width: 20px
  text-align: center
label
  font-size: 12px
  font-family: sans-serif
  margin-left: 10px
textarea
  margin-top: 10px
#settings
  font-family: sans-serif
  font-size: 12px
button
  margin-bottom: 5px
  background: green
  font-size: 14px
  border-radius: 5px
  border: none
  color: white
              
            
!

JS

              
                console.clear();
var tl = new TimelineMax(),
    resetBtn = $('button#reset'),
    playBtn = $('button#play'),
    pauseBtn = $('button#pause'),
    rewindBtn = $('button#rewind'),
    main = document.getElementById('main'),
    content = $('#container textarea').val(),
    direction = $('#direction option:selected').val(),
    tl = new TimelineMax(),
    repeats,
    speed,
    space,
    fontSize,
    topPad,
    bottomPad,
    stageWD = 720,
    stageHT = 300,
    pNews = [];

function newsTicker() {
  main.innerHTML = ""; // reset the container
  setVals(); // snag the settings from the form elements
  // create the main ticker container
  var ticker = document.createElement('div');
  ticker.setAttribute('id','ticker');
  // create the scroller container
  var scroller = document.createElement('div');
  scroller.setAttribute('id','scroller');
  
  var pNewsSettings, scrollerSettings;
  ticker.setAttribute('style',`font-size: ${fontSize}px; font-family: alphaEcho; color: white; overflow: visible; position: absolute;`);
  scroller.setAttribute('style','position: relative;');
  // a few styling diffs for horizontal vs vertical crawlers
  if( direction == "rl" || direction == "lr" ) {
    ticker.style.bottom = 0;
    ticker.style.whiteSpace = "nowrap";
    ticker.style.background = "blue";
    ticker.style.height = `${fontSize}px`;
    ticker.style.padding = `${topPad}px 0 ${bottomPad}px`;
    scroller.style.whiteSpace = 'nowrap';
    scroller.style.height = `${fontSize}px`;
    pNewsSettings = `position: relative; display: inline-block; white-space: nowrap;`;
  } else {
    ticker.style.width = `${stageWD}px`;
    ticker.style.height = `${stageHT}px`;
    ticker.style.background = 'transparent';
    ticker.style.padding = `${topPad}px 0 ${bottomPad}px;`;
    pNewsSettings = `position: relative; display: block; white-space: pre; text-align: center;`;
  }
  // set the starting position and the margin between repeats depending on which direction the scroller will animate
  switch( direction ) {
    case "rl":
      ticker.style.left = 0;
      pNewsMargin = `0 ${space}px 0 0`;
      scrollerSettings = {fromX: stageWD, multiplier: -1 }
    break;
    case "lr":
      ticker.style.right = 0;
      pNewsMargin = `0 0 0 ${space}px`;
      scrollerSettings = {fromX: stageWD*-1, multiplier: 1 }
    break;
    case "tb":
      pNewsMargin = `${space}px 0 0 0`;
      scrollerSettings = {fromY: stageHT*-1, multiplier: 1 }
    break;
    case "bt":
      pNewsMargin = `0 0 ${space}px 0`;
      scrollerSettings = {fromY: stageHT, multiplier: -1 }
    break;
  }
  
  // create a span to contain the text for each repeat
  for( var i = 0; i < repeats; i++ ) {
    pNews[i] = document.createElement('span');
    pNews[i].setAttribute('id',`scroller${i}`);
    pNews[i].setAttribute('style', pNewsSettings);
    pNews[i].style.margin = pNewsMargin;
    pNews[i].innerHTML = content;
    scroller.appendChild(pNews[i]);
  }
  // append all the created elements
  ticker.appendChild(scroller);
  main.appendChild(ticker);
  // get the height and width of the scroller container
  var sWidth = $(scroller).width();
  var sHeight = $(scroller).height();
  // create the animation depending on animation direction
  if( direction == "lr" || direction == "rl" ) {
    tl.fromTo(scroller, speed*repeats, {x: scrollerSettings.fromX}, {rotation: 0.01, force3D: true, x: (sWidth+stageWD)*scrollerSettings.multiplier, ease:Linear.easeNone});
  } else {
    tl.fromTo(scroller, speed*repeats, {y: scrollerSettings.fromY}, {rotation: 0.01, force3D: true, y: (sHeight+stageHT)*scrollerSettings.multiplier, ease:Linear.easeNone});
  }
  // hide the container after the animation
  tl.to(ticker,0.1,{autoAlpha: 0});
}

function setVals() {
  content = $('#container textarea').val();
  direction = $('#direction option:selected').val();
  repeats = parseInt($('#repeats').val());
  speed = parseFloat($('#speed').val());
  space = parseInt($('#space').val());
  fontSize = parseInt($('#font-size').val());
  topPad = parseInt($('#top-pad').val());
  bottomPad = parseInt($('#bottom-pad').val());
}

newsTicker();

pauseBtn.on("click", function(){
  tl.pause();
});

rewindBtn.on("click", function(){
  tl.pause().seek(0);
});

playBtn.on("click", function(){
  if( tl.duration() > 0 ) {
    tl.play();
  } else {
    tl.seek(0);
  }
});

resetBtn.on("click", function(){
  tl.pause().clear();
  resetChars();
  newsTicker();
});

function resetChars() {
  main.innerHTML = "";
}

              
            
!
999px

Console