css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <ul id="myUl">
    <li> | </li>
    <li style="color: red">Espresso</li>
    <li style="color: orange">Cappuccino</li>
    <li style="color: yellow">American</li>
    <li style="color: green">Tea</li>
    <li style="color: black">Milk</li>
    <li style="color: blue">Juice</li>
    <li> | </li>
</ul>
            
          
!
            
              /* liScroll styles */

.tickercontainer { /* the outer div with the black border */
	width: 100%; 
	min-height: 50px;
	margin: 0; 
	padding: 0;
	overflow: hidden; 
	text-align: center;
}
/* that serves as a mask. so you get a sort of padding both left and right */
.tickercontainer .mask { 
	position: relative;
	width: 100%;
	overflow: hidden;
}
ul.newsticker { /* that's your list */
position: relative;
list-style-type: none;
margin: 0;
padding: 0;

}
/* important: display inline gives incorrect results when you check for elem's width */
ul.newsticker li {
	float: left; 
	margin: 10px;
	padding: 0;
}

ul.er-controls{
	list-style: none;
	display: inline-block;
	padding: 0;
}
ul.er-controls > li{
	display: inline-block;
	padding: 0 10px;
	background: #f0f0f0;
	margin: 5px;
	border-radius: 5px;
	height: 40px;
	line-height: 40px;
}
ul.er-controls > li:hover{
	background: #f5f5f5;
	cursor: pointer;
}
            
          
!
            
              // endress-river
jQuery.fn.endlessRiver = function (settings) {
    settings = jQuery.extend({
        speed: 100,
		pause: true,
		buttons: false
    }, settings);
    return this.each(function(){
		var j = jQuery;
        var $line = j(this);
        var id = "ER_"+ new Date().getTime();
        $line.wrap("<div id=\""+id+"\"></div>");
		$line.css({
			margin: "0 !important",
			padding: "0 !important"
		});
        var currentSpazio,currentTempo;
        var run = true;
        var initialOffset = $line.offset().left;
		var lineWidth = 1;
        $line.children("li.tick-clones").remove();
		//elimina cloni se ci sono - Serve in caso io aggiorni dinamicamente il contenuto
        $line.addClass("newsticker");
        var $mask = $line.wrap("<div class='mask'></div>");
        var $tickercontainer = $line.parent().wrap("<div class='tickercontainer'></div>");
		var elements = $line.children("li");
		var fill = function(){
			lineWidth = 1;
			$line.append(elements.clone(true).addClass("tick-clones"));
			$line.children("li").each(function (i) {
				lineWidth += j(this, i).outerWidth(true);
				//outherWidth con argomento true ritorna larghezza compresi margini
			});
			
		}
		var l = $tickercontainer.outerWidth(true);
		while(lineWidth<l) fill();
		$line.width(lineWidth);
        $line.height($line.parent().height());
        function scrollnews(spazio, tempo) {
            $line.animate({left: '-=' + spazio}, tempo, "linear", function () {
                $line.children("li:first").appendTo($line);
                $line.css("left", 0);
                currentSpazio = $line.children("li:first").outerWidth(true);
                currentTempo = tempo / spazio * currentSpazio;
                if(run)
                	scrollnews(currentSpazio, currentTempo);
            });
        }
        $line.trigger('test');
        //BOOT
        currentSpazio = $line.children("li:first").outerWidth(true);
        currentTempo = currentSpazio / settings.speed * 1000;
        //x 1000 perch� tempo � in millisecondi
        scrollnews(currentSpazio, currentTempo);
		function setHover(){
			$line.off( "mouseenter mouseleave" );
			$line.hover(pause,resume);
		}

		function pause(){
			j("#"+id+" .er-controls > .pause").toggleClass("play glyphicon-play pause glyphicon-pause");
			run = false;
			$line.stop();
		}

		function resume() {
			j("#"+id+" .er-controls > .play").toggleClass("play glyphicon-play pause glyphicon-pause");
			run = true;
			var offset = $line.offset().left;
			var residualSpace = offset + $line.children("li:first").outerWidth(true) - initialOffset;
			var residualTime = currentTempo / currentSpazio * residualSpace;
			scrollnews(residualSpace, residualTime);
		}
		if(settings.pause) setHover();
		
		if(settings.buttons){

			var $buttons = j('<ul class="er-controls">'+
			'<li class="prev glyphicon glyphicon-chevron-left"></li>'+
			'<li class="pause glyphicon glyphicon-pause"></li>'+
			'<li class="next glyphicon glyphicon-chevron-right"></li>'+
			'</ul>');
			$buttons.insertAfter($tickercontainer);
			//DELEGATE IS BETTER!
			j("body").on("click", "#"+id+" .er-controls > .pause", function(){
				if(!run) return false;
				j(this).toggleClass("pause glyphicon-pause play glyphicon-play");
				$line.off('mouseenter mouseleave');
				run = false;
			});

			j("body").on("click", "#"+id+" .er-controls > .play", function(){
				if(run) return false;
				j(this).toggleClass("pause glyphicon-pause play glyphicon-play");
				run = true;
				setHover();
				var offset = $line.offset().left;
				var residualSpace = offset + $line.children("li:first").outerWidth(true) - initialOffset;
				var residualTime = currentTempo / currentSpazio * residualSpace;
				scrollnews(residualSpace, residualTime);
			});

			var moving = false;
			
			j("body").on("click", "#"+id+" .er-controls > .next", function(){
				if(run){
					j("#"+id+" .er-controls > .pause").toggleClass("pause glyphicon-pause play glyphicon-play");
					run = false;
					return;
				}
				if(moving) return false;
				var spazio = $line.children("li:first").outerWidth(true);
        		var tempo = spazio / settings.speed * 1000;
        		moving = true;
				$line.stop(true,true).animate({left: '-=' + spazio}, tempo, "linear", function () {
                	$line.children("li:first").appendTo($line);
                	$line.css("left", 0);
                	moving = false;
            	});

            });

			j("body").on("click", "#"+id+" .er-controls > .prev", function(){
				if(run){
					j("#"+id+" .er-controls > .pause").toggleClass("pause glyphicon-pause play glyphicon-play");
					run = false;
					return;
				} 
				if(moving) return false;
				var spazio = $line.children("li:last").outerWidth(true);
				$line.css("left", "-"+spazio+"px");
				$line.children("li:last").prependTo($line);
        		var tempo = spazio / settings.speed * 1000;
        		moving = true;
				$line.stop(true,true).animate({left: '+=' + spazio}, tempo, "linear", function(){
					moving = false;
				});
				
			});			
		}
			
    });
};


// endress-riverカスタムを実行!
$("#myUl").on('test',function() {
  console.log('TEST!!!!!');
  $(this).after('<p>追加してみたよ!</p>')
}).endlessRiver();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console