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.

            
              .container
	.row.d-flex.justify-content-center
		#tomato-timer.card.col-lg-6.col-md-8.col-sm-10.col-xs-12.mt-5
			header.mt-3
				h1 Pomodoro Timmer
			section.card-body
				.btn-add
					i.fa.fa-plus
				.btn-sub
					i.fa.fa-minus
				.timer-display
					.btn-action
						span.loading
						span.fa
					.timer
						h3#session {{ displaySession }}
						p#status {{ displayStatus }}
				section.setting-break
					h3 Break Length
					p
						span.fa.fa-minus.btn-break-sub
						span#break {{ displayBreak }}
						span.fa.fa-plus.btn-break-add
				a.btn-reset
					span Reset
            
          
!
            
              @import 'https://fonts.googleapis.com/css?family=Open+Sans|Pacifico'

$main-color: #66CDAA
$secondary-color: #0881AF
$red-color: #EE2C2C
$green-color: #228B22

mt-50
	margin-top: 50px

h1
	font-family: Pacifico
	color: $main-color
	text-align: center
	text-shadow: 2px 2px #0881AF

.btn-add,
.btn-sub
	background-color: $green-color
	border-radius: 50%
	position: absolute 
	top: 40%
	font-size: 1.5em
	box-shadow: 0 5px 2.5px -2.5px rgba(1, 1, 1, 0.3)
	transform:translate(0, -50%)
	&:active
				transform: translate(0,-25px) scale(1.1,1.1)
				box-shadow: 0 10px 2.5px -2.5px rgba(1,1,1,0.3)

.btn-sub
	padding: 10px 20px
	margin-left: 6%
	left: 0
.btn-add
	padding: 10px 20px
	margin-right: 6%
	right: 0

.timer-display
	border: 5px dashed $red-color
	border-radius: 50%
	height: 250px
	width: 250px
	position: relative
	overflow: hidden
	transition: all ease-in-out 300ms
	margin: 0px auto 0px
	&._isBreak
		transition: all ease-in-out 300ms
		background-color: $green-color
		border-color: lighten($green-color,0.2)
			
	&._isPaused
		transition: all ease-in-out 300ms
		background-color: #fff
		border-color: #333

.btn-action,
.timer
	position: absolute
	top: 50%
	left: 50%
	transform: translate(-50%,-50%)

.btn-action
	width: 100%
	height: 100%
	cursor: pointer
	z-index: 999
	& > span
		position: absolute 
		display: block
		width: 100%
		height: 100%
		background-color: transparent
	& > .fa
		opacity: 0
		width: 100%
		height: 100%
		line-height: 2
		text-align: center
		color: #000
		font-size: 6em
	& > .loading
		background-color: $red-color
		width: 100%
		height: 100%
		opacity: 0
		transition: all 300ms cubic-bezier(0,-0.66,0.97,1.76)
	&:hover > .fa
		opacity: 0.7
	
.timer
	h3
		font-size: 2.5em
		font-weight: 700
	p
		font-size: 1.5em
	
	
.setting-break
	text-align: center
	margin: 10px 0 10px
	padding: 10px
	color: $green-color
	border: 5px solid $green-color
	border-radius: 20px
	h3
		font-size: 1em
		line-height: 1.5
		margin-bottom: 5px
	p
		display: block
		width: 100%
	span
		display: inline-block
	span.fa
		font-size: 1em
		width: 25px
		height: 25px
		padding: 5px
		background-color: $green-color
		box-shadow: 0 5px 2.5px -2.5px rgba(1,1,1,0.3)
		color: #000
		border-radius: 100%
		cursor: pointer
		transition: all 300ms ease-in-out
		&:active
			transform: scale(1.5)

	.break
				margin: 0 25px
				font-size: 1.5em
				font-weight: 700
	
span.fa.fa-plus
	margin-left: 10px
span.fa.fa-minus
	margin-right: 10px

.btn-reset
		margin-top: 15px
		text-align: center
		display: block
		width: 100%
		padding: 10px
		background-color: $main-color
		color: #fff
		font-size: 1.5em
		font-weight: 700
		border: none
		border-radius: 10px
		cursor: pointer
		transform-origin: center
		perspective-origin: center
		span
			display: block
			width: 100%
			background-color: transparent
		&:hover
			background-color: darken($main-color,10%)
	
.btn-animation
		animation: btn-shake 200ms ease-in-out forwards
		& > span
			animation: btn-shake 200ms ease-in-out reverse forwards
	
// Animarion
@keyframes btn-shake
	0%
		transform: translate(-5%,0)
	20%
		transform: translate(0px,0)
	50%
		transform: translate(5%,0)
	100%
		transform: translate(0,0)
            
          
!
            
              (function(){
	var vm = new Vue({
		el: "#tomato-timer",
		data: {
			sessionTotal: 0,
			session: 25,
			breakTotal: 0,
			break: 5,
			lap: 1,
			isPaused: true,
			isBreak: false
		},
		computed: {
			displaySession: function(){
				if(this.isBreak){
					return this.secToString(this.break);
				}
				return this.secToString(this.session);
			},
			displayBreak: function(){
				return this.secToString(this.break);
			},
			displayStatus: function(){
				if(this.isBreak){
					return "Break Session"
				}
				if(this.isPaused){
					return "Paused"
				}
				return "Session "+ this.lap;
			},
			progress: function(){
				if(this.isBreak){
					return this.getPercent("break");
				}else{
					return this.getPercent("session");
				}
			}
		},
		methods: {
			secToString : function(sec){
				var hours, minutes, seconds, result;
				seconds = Math.floor((sec)%60);
				minutes = Math.floor((sec/60)%60);
				hours = Math.floor((sec/60/60)%60);
				result = [hours, minutes, seconds].map(function(val){

					if(val < 10){
						return "0"+val;
					}

					return val;
				});
				// Hide hours when don't need
				if(result[0] == "00") {
					result.shift();
				}
				return result.join(":");
			},
			getPercent: function(value){
				return ((this[value] / this[value+"Total"]) * 100) ;
			},
			hideSettings: function(toggle){
				var $settings = $(".btn-sub, .btn-add, .setting-break");
				if(toggle){
					$settings.hide(400);
				} else {
					$settings.show(300)
				}
			},
			reset: function(){
				this.stopTimer();
				this.lap = 1;
				this.isBreak = false;
				this.isPaused = true;
				this.session = this.sessionTotal;
				this.break = this.breakTotal;
				this.sessionTotal = 0;
				this.breakTotal = 0;
			},
			startTimer: function(timer){
				var that = this;
				timerSession = setInterval(function(){
					vm[timer]--;
				},1000);
			},
			stopTimer: function () {
				if(timerSession){
					clearInterval(timerSession);
				}
			}
		},
		watch: {
			progress: function(progress){
				var	translateY = "translateY(" + (progress) + "%)",
					opacity = 1 - (progress / 110);
				$(".loading").css("transform", translateY);
				$(".loading").css("opacity",opacity);
			},
			isPaused: function(isPaused){
				var timer = this.isBreak ? "break" : "session";
				var $icon = $(".btn-action > .fa");
				if(!isPaused){
					if(this[timer] <= 0){
						this.stopTimer();
					}
					this.startTimer(timer);
					$icon
						.addClass("fa-pause")
						.removeClass("fa-play");
				} 
				if(isPaused){
					this.stopTimer();
					$icon
						.addClass("fa-play")
						.removeClass("fa-pause");
				}
			},
			isBreak: function(isBreak){
				if(isBreak){
					this.startTimer("break");
					$(".timer-display").addClass("_isBreak");
					$(".loading").css("background-color","#EE2C2C");
				} else {
					this.startTimer("session");
					$(".timer-display").removeClass("_isBreak");
					$(".loading").css("background-color","#228B22");
				}
			},
			session: function(sessionVal){
				if(!this.isBreak && sessionVal <= 0){
					this.stopTimer();
					this.break = this.breakTotal;
					this.isBreak = true;
				}
			},
			break: function(breakVal){
				if(this.isBreak && breakVal <= 0){
					this.stopTimer();
					this.lap++;
					this.session = this.sessionTotal;
					this.isBreak = false;
				}
			}
		}
	});
	
	$('.btn-add').on('mousedown', function(){
		sessionInterval = setInterval(function(){
			vm.session++
		}, 100);
	}).on("mouseup mouseleave", function(){
		clearInterval(sessionInterval);
		vm.resetSeasonTotal();
	});
	
	$('.btn-sub').on('mousedown', function(){
		sessionInterval = setInterval(function(){
			if(vm.session > 0){
				vm.session--
			}
		}, 100);
	}).on("mouseup mouseleave", function(){
		clearInterval(sessionInterval);
		resetSeasonTotal();
	});
	
	$('.btn-break-add').on('mousedown', function(){
		breakInterval = setInterval(function(){
			vm.break++
		}, 100);
	}).on("mouseup mouseleave", function(){
		clearInterval(breakInterval);
		resetBreakTotal();
	});

	$('.btn-break-sub').on('mousedown', function(){
		breakInterval = setInterval(function(){
			if(vm.break > 0){
				vm.break--
			}
		}, 100);
	}).on("mouseup mouseleave", function(){
		clearInterval(breakInterval);
		resetBreakTotal();
	});
	
	$(".btn-action").on("click", function(){
		// Initial Action
		if(vm.sessionTotal === 0 && vm.breakTotal === 0) {
			vm.sessionTotal = vm.session;
			vm.breakTotal = vm.break;
		}

		// Toggle button (Play and Pause)
		if(!vm.isPaused){
			// Triger pause event
			$(".timer-display").addClass("_isPaused");
			vm.isPaused = true;
			$(".btn-reset").show(400);
		} else {
			// Triger play event
			$(".timer-display").removeClass("_isPaused");
			vm.hideSettings(true);
			vm.isPaused = false;
			$(".btn-reset").hide(400);
		}
	});
	
	$(".btn-reset").hide();
	
	$(".btn-reset").on('click', function(){
		$(this).addClass('btn-animation');
		$(this).one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
				$(this).removeClass('btn-animation');
		});
		// Show settings
		vm.hideSettings(false);

		// Reset to Default
		vm.reset();
		$(this).hide(400);
	});
})();
            
          
!
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