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

              
                <div class="ui-newsticker">
  <ul class="ui-newsticker-list">
    <li class="ui-newsticker-item">
      That open was light. After also shall first rule third every place spirit light. Beginning together their hath, winged firmament.
    </li>
    <li class="ui-newsticker-item">
      That creature his bring waters female morning place Give bearing in isn't from. Without his fowl void bearing. Blessed give.
    </li>
    <li class="ui-newsticker-item">
      And also. Firmament and Give. Sea replenish gathered give in for whose tree their a said multiply abundantly give years.
    </li>
  </ul>
</div>
              
            
!

CSS

              
                body {
  padding: 15px;
}

@mixin ui-newsticker-mixin($namespace: ui) {
  $background-color: #bbb;
  $background-hover-color: #ddd;
  $radius: 5px;
  $font-color: #402726;
  $font-family: verdana;
  $font-size: 13px;
  $top: 8px;
  $height: 30px;
  $interval: 10px;

  .#{$namespace}-newsticker {
    @include rounded-box;
    background: $background-color;
    color: $font-color;
    cursor: default;
    font-family: $font-family;
    font-weight: bold;
    font-size: $font-size;
    line-height: $font-size*1.2;
    padding: 0 $interval 0 $interval;
    height: $height;
    position: relative;
    overflow: hidden;
    will-change: transform;
    &:hover{
      background: $background-hover-color;
    }
  }
  .#{$namespace}-newsticker-list{
    position: absolute;
    overflow: hidden;
    transition-property: transform;
    transition-timing-function: ease;
  }
  .#{$namespace}-newsticker-item {
    height: $height;
    overflow: hidden;
    white-space: nowrap;
  }
}

@mixin rounded-box($radious: 10px){
  border-radius: $radious;
  -webkit-border-radius: $radious;
  -moz-border-radius: $radious;
}

@include ui-newsticker-mixin(ui);
              
            
!

JS

              
                (function($) {
  $.fn.newsticker = function(opts) {
    var $newsticker = $(this),
      $frame = $newsticker.find('.ui-newsticker-list'),
      $item = $frame.find('.ui-newsticker-item'),
      $next = {},
      startPos = 0,
      stop = false,
      config = $.extend({}, {
        height: 30,
        speed: 800,
        interval: 3000,
        move: null
      }, opts);

    function Newsticker(config) {
      this.config = config;
      this.init($newsticker, config.height);
    }

    Newsticker.prototype = {
      index: 0,
      calStartPos: function(height, lineHeight) { //calculate start position
        return (height - lineHeight) / 2;
      },
      setStartPos: function(frame, pos) { //set start position
        frame.css('top', pos);
      },
      suspend: function() { //suspend newsticker
        $newsticker.on('mouseover mouseout', function(e) {
          stop = e.type === 'mouseover';
        });
      },
      move: function() { //activate newsticker
        if ($.isFunction(config.move)) {
          config.move.call(this);
        } else {
          let start = null;

          const tick = (timestamp) => {
            let progress = timestamp - start;
            if (start === null) { start = timestamp; }

            if (progress < config.interval || stop) {
              window.requestAnimationFrame(tick);
            } else {
              let targetHeight = 0;

              if (this.index < $item.length - 1) {
                this.index++;
              } else {
                this.index = 0;
              }

              targetHeight = config.height * this.index;

              $frame.css({
                'transform': `translateY(-${targetHeight}px)`,
              });

              start = timestamp;
              window.requestAnimationFrame(tick);
            }
          }

          requestAnimationFrame(tick);
        }
      },
      init: function(ticker, height) { //init settings
        var $ticker = $(ticker),
          $frame = $ticker.find('.ui-newsticker-list'),
          $firstItem = $frame.find('.ui-newsticker-item').eq(0),
          lineHeight = parseInt($ticker.css('lineHeight').split('px')[0]) || 15;

        $ticker.css('height', height); //set customized height
        startPos = this.calStartPos(height, lineHeight);
        this.setStartPos($frame, startPos);
        $frame.css({
          'transition-duration': `${config.interval - 100}ms`,
        });
        this.suspend(); //trigger mouse event for suspending newsticker
        this.move(); //activate newsticker
      }
    };

    return new Newsticker(config);
  };
})(jQuery);

$(function() {
  $('.ui-newsticker').newsticker();
});
              
            
!
999px

Console