123

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.

            
              <div id="stockApp" class="app" data-symbols="
	AMD, DIA, XLF, XLK,
	GS, MS, JPM, AAPL,
	AMZN, NFLX, BND, BIV,
	GLD, EFC, EARN, XOM,
	WMT, JNJ, GE, T,
	KO, DIS
">
	<div class="ticker">
		<div class="ticker-sidebar">
			<div class="ticker-sidebar-body">
				<h3 class="ticker-title">

					<h1>   Alphi Finance</h1>
				</h3>
				
			</div>
			<div class="ticker-sidebar-footer">
				<div class="ticker-text-ellipsis">
					<svg viewBox="0 0 32 32" height="11" fill="none" stroke="currentcolor" stroke-width="3">
						<path d="M28 22 L28 30 4 30 4 22 M16 4 L16 24 M8 16 L16 24 24 16" />
					</svg>
					<small><i>{{ lastUpdated }}</i></small>
				</div>
				<div v-show="chunkSize !== symbols.length" class="ticker-btn-group">
					<button v-on:click="previousPage" class="ticker-btn">
						<svg viewBox="0 0 32 32" width="8px">
							<path fill="currentColor" d="M22 30 L6 16 22 2 Z" />
						</svg>
					</button>
					<button v-on:click="resetPage" class="ticker-btn">
						{{ activePage + 1 }}
					</button>
					<button v-on:click="nextPage" class="ticker-btn">
						<svg viewBox="0 0 32 32" width="8px">
							<path fill="currentColor" d="M10 30 L26 16 10 2 Z" />
						</svg>
					</button>
				</div>
			</div>
		</div>
		<div class="ticker-body">
			<div v-for="item in quotedSymbols[activePage]" v-bind:key="item.symbol" class="ticker-item">
				<h2 class="ticker-item-symbol ticker-animated" :class="{
					'ticker-fade-down': transitioning
				}">
					{{ item.symbol }}
				</h2>
				<h3 class="ticker-item-price">
					<a class="ticker-animated" :class="{
						'ticker-fade-down': transitioning
					}" :href="item.symbol | symbolUrl" style="transition-delay: 0.1s" target="_blank">
						{{ item.quote.latestPrice | formatPrice }}
					</a>
				</h3>
				<div class="ticker-item-delta">
					<small class="ticker-text-muted ticker-animated" :class="{
						'ticker-fade-down': transitioning
					}" style="transition-delay: 0.15s">
						<i :class="{
							'ticker-text-danger': item.quote.changePercent < 0,
							'ticker-text-success': item.quote.changePercent > 0
						}">{{ item.quote.change }}</i>&nbsp;|&nbsp;<i :class="{
							'ticker-text-danger': item.quote.changePercent < 0,
							'ticker-text-success': item.quote.changePercent > 0
						}">{{ item.quote.changePercent | formatChangePercent }}</i>
					</small>
				</div>
			</div>
		</div>
	</div>
</div>
            
          
!
            
              /* Scaffold */
body {
	-moz-osx-font-smoothing: grayscale;
	-webkit-font-smoothing: antialiased;
	align-items: center;
	background: #cddccd;
	background: linear-gradient(25deg, coral, aqua);
	color: #605D4E;
	display: flex;
	font-family: futura;
	height: 100vh;
	text-rendering: optimizeLegibility;
}

.app {
	margin: 0 auto;
	max-width: 1140px;
	width: 100%;
}

/* Animations */
.ticker-animated {
	display: inline-block;
	transform: translateY(0);
	transition: all 0.4s;
}

.ticker-fade-down {
	opacity: 0;
	transform: translateY(-5px);
	transition-duration: 0.2s;
}

/* Ticker */
.ticker {
	background-color: #fff;
	border-radius: 5px;
	border: 1px solid rgba(96, 93, 78, .33);
	box-shadow: 0 4px 8px rgba(96, 93, 78, .2);
	display: flex;
}

.ticker h2,
.ticker h3 {
	font-family: 'Asap Condensed';
	font-weight: 600;
}

.ticker a,
.ticker a:hover,
.ticker a:focus {
	color: #516672;
	text-decoration: none;
}

.ticker.compact {
	display: block;
}

.ticker.compact .ticker-body {
	overflow-x: auto;
	width: auto;
}

.ticker.compact .ticker-item {
	min-width: 100px;
}

.ticker.compact .ticker-sidebar {
	border-bottom: 1px solid rgba(73, 78, 81, .2);
	border-right: none;
	width: auto;
}

.ticker.compact .ticker-sidebar-footer {
	border-bottom-left-radius: 0;
}

.ticker-body {
	display: flex;
	overflow-x: hidden;
	overflow-y: hidden;
	width: 75%;
}

.ticker-btn {
	border: 4px solid rgba(96, 93, 78, .2);
	background-color: rgb(244, 250, 255);
	color: rgba(73, 78, 81, 1);
	cursor: pointer;
	display: inline-block;
	font-weight: 600;
	padding: 5px 10px;
	text-align: center;
	vertical-align: middle;
	white-space: nowrap;
}

.ticker-btn:hover,
.ticker-btn:focus {
	background-color: rgb(234, 240, 245);
}

.ticker-btn-group {
	display: flex;
	margin-left: auto;
	vertical-align: middle;
}

.ticker-btn-group .ticker-btn + .ticker-btn {
	margin-left: -1px;
}

.ticker-item {
	border-right: 1px solid rgba(96, 93, 78, .2);
	display: block;
	padding: 7.5px;
	text-align: center;
	width: 20%;
}

.ticker-item:last-child {
	border-right: none;
}

.ticker-item-delta {
	margin-bottom: 5px;
}

.ticker-item-price {
	margin-bottom: 4px;
	margin-top: 3px;
}

.ticker-item-symbol {
	margin-bottom: 0;
	margin-top: 5px;
}

.ticker-sidebar {
	background-color: rgba(171, 186, 171, .1);
	border-right: 1px solid rgba(73, 78, 81, .2);
	width: 25%;
}

.ticker-sidebar-body {
	padding: 7.5px 15px;
}

.ticker-sidebar-footer {
	align-items: center;
	background-color: rgba(255, 255, 255, .66);
	border-bottom-left-radius: 5px;
	border-top: 1px solid rgba(96, 93, 78, .2);
	display: flex;
	padding-left: 15px;
}

.ticker-sidebar-footer .ticker-btn-group > .ticker-btn {
	border-bottom: none;
	border-top: none;
}

.ticker-sidebar-footer .ticker-btn-group > .ticker-btn:first-child {
	border-bottom-left-radius: 0;
	margin-left: 0;
}

.ticker-sidebar-footer .ticker-btn-group > .ticker-btn:last-child {
	border-right: none;
}

.ticker-thumbnail {
	border-radius: 50%;
	box-shadow: 0 1px 1px rgba(96, 93, 78, .66);
	margin-right: 2px;
	width: 15px;
}

.ticker-title {
	margin-bottom: 5px;
	margin-top: 0;
	border-bottom: 1px solid rgba(96, 93, 78, .2);
}

/* Utilities */
.ticker-text-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticker-text-danger { color: red; }
.ticker-text-muted { color: rgba(73, 78, 81, .5); }
.ticker-text-success { color: green; }
.ticker-text-underline { text-decoration: underline; }

/* Media Queries */
@media screen and (max-width: 768px) {
	.ticker {
		display: block;
	}

	.ticker-body {
		overflow-x: auto;
		width: auto;
	}

	.ticker-item {
		min-width: 100px;
	}

	.ticker-sidebar {
		border-bottom: 1px solid rgba(73, 78, 81, .2);
		border-right: none;
		width: auto;
	}

	.ticker-sidebar-footer {
		border-bottom-left-radius: 0;
	}
}
            
          
!
            
              const app = new Vue({
	el: '#stockApp',
	data: {
		activePage: 0,
		baseUrl: 'https://api.iextrading.com/1.0/stock/market/batch',
		chunkSize: 5,
		filters: ['change', 'changePercent', 'companyName', 'latestPrice', 'marketCap'],
		lastUpdated: false,
		quotes: [],
		refreshInterval: 60,
		symbols: [],
		transitioning: false,
		updateLoop: false
	},
	computed: {
		quotedSymbols() {
			let symbols = this.symbols.map((symbol) => {
				return {
					symbol: symbol,
					quote: (this.quotes[symbol]) ? this.quotes[symbol].quote : []
				};
			});

			return this.chunkBy(symbols, this.chunkSize);
		}
	},
	filters: {
		formatChange(value) {
			if (!value) return 'N/A';

			return value.toLocaleString('en', { 'minimumFractionDigits': 2 });
		},
		formatChangePercent(value) {
			if (!value) return 'N/A';

			return (value * 100).toFixed(1) + '%';
		},
		formatPrice(value) {
			if (!value) return 'N/A';

			let options = {
				minimumFractionDigits: 2,
				style: 'currency',
				currency: 'USD'
			};

			return value.toLocaleString('en', options);
		},
		formatMarketCap(value) {
			if (!value) return 'N/A';

			let marketCap;
			let suffix;

			if (value >= 1e12) {
				marketCap = value / 1e12;
				suffix = 'T';
			} else if (value >= 1e9) {
				marketCap = value / 1e9;
				suffix = 'B';
			} else {
				marketCap = value / 1e6;
				suffix = 'M';
			}

			let digits = marketCap < 10 ? 2 : 0;

			return '$' + marketCap.toFixed(digits) + suffix;
		},
		symbolUrl(value) {
			return `https://iextrading.com/apps/stocks/${value}`;
		}
	},
	methods: {
		chunkBy(values, amount) {
			let index = 0;
			let resIndex = 0;
			let results = [];

			while (index < values.length) {
				results[resIndex++] = values.slice(index, index += amount);
			}

			return results;
		},
		fetchQuotes() {
			this.transitionOut().then(() => {
				fetch(
					`${this.baseUrl}?types=quote,chart
					&range=1m&last=5
					&symbols=${this.symbols.join(',')}
					&filter=${this.filters.join(',')}`
				).then((response) => response.json()).then((json) => {
					this.quotes = json;
				});

				this.lastUpdated = new Date().toLocaleString();
				this.transitionIn();
			});
		},
		previousPage() {
			if (!this.transitioning) {
				this.transitionOut().then((response) => {
					this.activePage = (this.activePage <= 0) ? this.quotedSymbols.length - 1 : this.activePage - 1;
				});
			}
		},
		nextPage() {
			if (!this.transitioning) {
				this.transitionOut().then((response) => {
					this.activePage = (this.activePage < this.quotedSymbols.length - 1) ? this.activePage + 1 : 0;
				});
			}
		},
		resetPage() {
			if (!this.transitioning && this.activePage) {
				this.transitionOut().then((response) => {
					this.activePage = 0;
				});
			}
		},
		toggleChunkSize() {
			if (window.innerWidth > 576 && this.chunkSize > 5) {
				this.chunkSize = 5;
			} else if (window.innerWidth <= 576 && this.chunkSize < this.symbols.length) {
				this.chunkSize = this.symbols.length;
			}
		},
		transitionIn() {
			setTimeout(() => {
				this.transitioning = false;
			}, 200);
		},
		transitionOut() {
			this.transitioning = true;

			return new Promise((resolve) => {
				setTimeout(resolve, 400);
			});
		}
	},
	watch: {
		activePage() {
			this.transitionIn();
		},
		symbols(value) {
			if (value.length) {
				this.fetchQuotes();
				this.updateLoop = setInterval(this.fetchQuotes, this.refreshInterval * 1000);
			}
		}
	},
	mounted() {
		this.symbols = this.$el.dataset.symbols.replace(/\s/g, '').split(',');
		
		this.toggleChunkSize();
		
		window.addEventListener('resize', () => {
			this.toggleChunkSize();
		});
	}
});
            
          
!
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.

Console