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="mq-container">
  <div class="mq-title-wrap">
    <h3 class="mq-title">hi</h3>
  </div>
</div>
<div class="mq-container">
  <div class="mq-title-wrap">
    <h3 class="mq-title">woop woop</h3>
  </div>
</div>
<div class="mq-container">
  <div class="mq-title-wrap">
    <h3 class="mq-title">Dies ist ein extrem langer text</h3>
  </div>
</div>
<div class="mq-container">
  <div class="mq-title-wrap">
    <h3 class="mq-title">das geht auch</h3>
  </div>
</div>
              
            
!

CSS

              
                .mq-container{
  position: relative;
  margin: 0 auto;
  padding: 0;
  width: 700px;
  height: 100px;
	margin-bottom: 20px;
  background-color: yellow;
	overflow: hidden;
}

.mq-title-wrap{
  padding: 0;
  margin: 0;
  position: absolute;
  bottom: 0;
  white-space: nowrap;
}

.mq-title{
  display: inline-block;
  font-size: 60px;
  margin: 0;
  padding: 0;
  margin-right: 20px;
}


              
            
!

JS

              
                var step = -0.05;
var ids = [];


function newId(){
	var nId;
	do {
		nId = makeId();
	} while (hasClone(nId));
	ids.push(nId);
}

function hasClone(i){
	ids.forEach(function(id){
			if (i == id){
					return true;
					}
	});
	return false;
}

function makeId() {
  var text = "";
  var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}



$(".mq-container").each(function(){
	
	var cont = $(this);
  var titleWrap = $(this).find(".mq-title-wrap");
  var title = $(this).find(".mq-title-wrap").find(".mq-title");

	var cW = cont.width();
	var t = title.outerWidth(true);
	var tW;
	var pos;
	var percentOfParent;

	//init here
	// create duplicates
	function init() {
		var tElem;
		tW = titleWrap.outerWidth();
		do {
			tElem = title.first()
				.clone();
			tElem.appendTo(titleWrap);
			tW = titleWrap.outerWidth();
		} while (cW + t * 3 >= tW);
		//cW + t * 3 >= tW
		tW = titleWrap.outerWidth();
	}
	//--------

	function setToOffset() {
		percentOfParent = t / cW * -100;
		pos = percentOfParent;
		resetLeft();
	}

	function resetLeft() {
		setLeft(percentOfParent);
	}

	function setLeft(l) {
		titleWrap.css("left", l + "%");
	}

	function animate() {
		var id = setInterval(frame, 1);
	}

	function frame() {
			if (step > 0 && pos > percentOfParent) {
				pos = pos+percentOfParent;
			} else if (step < 0 && pos < percentOfParent*2){
				pos = pos-percentOfParent;
			} else if (step != 0) {
				pos+=step;
			}
			setLeft(pos);
	}

	init();
	setToOffset();
	animate();
	console.log(percentOfParent);

});
              
            
!
999px

Console