Popular Posts

Creating a Custom Animated Range Slider using HTML, CSS & JavaScript

A range slider lets the user to select a range of value within a specified minimum and maximum value. In this blog, you will learn how to create a custom animated range slider using HTML, CSS and JavaScript. 

HTML
<div class="range-input">
  <input type="range" min="0" max="100" value="0" step="10">
  <div class="value">
    <div></div>
  </div>
</div>
CSS
body {
  background:#4471ef;
  font-family:"Raleway",sans-serif;
}
.range-input {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  background:#eee;
  padding:10px 20px;
  display:flex;
  align-items:center;
  border-radius:10px;
}
.range-input input {
  -webkit-appearance:none;
  width:200px;
  height:2px;
  background:#4471ef;
  border:none;
  outline:none;
}
.range-input input::-webkit-slider-thumb {
  -webkit-appearance:none;
  width:20px;
  height:20px;
  background:#eee;
  border:2px solid #4471ef;
  border-radius:50%;
}
.range-input input::-webkit-slider-thumb:hover {
  background:#4471ef;
}
.range-input .value {
  color:#4471ef;
  text-align:center;
  font-weight:600;
  line-height:40px;
  height:40px;
  overflow:hidden;
  margin-left:10px;
}
.range-input .value div {
  transition:all 300ms ease-in-out;
}
JS
let rangeInput = document.querySelector(".range-input input");
let rangeValue = document.querySelector(".range-input .value div");

let start = parseFloat(rangeInput.min);
let end = parseFloat(rangeInput.max);
let step = parseFloat(rangeInput.step);

for(let i=start;i<=end;i+=step){
  rangeValue.innerHTML += '<div>'+i+'</div>';
}

rangeInput.addEventListener("input",function(){
  let top = parseFloat(rangeInput.value)/step * -40;
  rangeValue.style.marginTop = top+"px";
});

Building a Basic Paint/Sketch App using HTML, CSS & JavaScript

This post is about how to build a basic paint/ sketch application using HTML, CSS and JavaScript. Here, we have used p5.js library to create the canvas of paint app. We have used some useful features of p5.js to build this amazing sketch app such as, "mouseDragged" event , "mouseX, mouseY", "pmouseX, pmouseY" special variables and "background", "fill", "stroke", "saveCanvas" function.



Library used
<link type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.6/p5.min.js"></script>
HTML
<div class="app">
  <div class="controls">
    <div class="title">Sketch</div>
    <div class="type">
      <input type="radio" name="pen-type" id="pen-pencil" checked>
      <label for="pen-pencil">
        <i class="fa fa-pencil"></i>
      </label>
      <input type="radio" name="pen-type" id="pen-brush">
      <label for="pen-brush">
        <i class="fa fa-paint-brush"></i>
      </label>
    </div>
    <div class="size">
      <label for="pen-size">Size</label>
      <input type="range" id="pen-size" min="1" max="50">
    </div>
    <div class="color">
      <label for="pen-color">Color</label>
      <input type="color" id="pen-color" value="#000">
    </div>
    <div class="actions">
      <button id="reset-canvas">Reset</button>
      <button id="save-canvas">Save</button>
    </div>
  </div>
  <div id="canvas-wrapper"></div>
</div>
CSS
* {
  margin:0px;
  padding:0px;
  box-sizing:border-box;
}
body {
  background:#555;
}
.app {
  position:fixed;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  width:650px;
  height:650px;
  font-family:"Raleway", sans-serif;
}
.app .controls {
  height:50px;
  display:flex;
  align-items:center;
  background:#ddd;
  padding:0px 10px;
}
.app .controls .title {
  font-weight:600;
  color:#222;
  width:80px;
}
.app .controls .type,
.app .controls .size,
.app .controls .color {
  margin: 0px 10px;
}
.app .controls .type input {
  display:none;
}
.app .controls .type label {
  width:30px;
  height:30px;
  display:inline-block;
  text-align:center;
  line-height:30px;
  margin:0px 2px;
  cursor:pointer;
}
.app .controls .type input:checked + label {
  background:#111;
  color:#eee;
  border-radius:50%;
}
.app .controls .size input {
  height:10px;
}
.app .controls .actions {
  flex:1;
  text-align:right;
}
.app .controls .actions button {
  padding:5px 10px;
  cursor:pointer;
}
JavaScript
function _(selector){
  return document.querySelector(selector);
}
function setup(){
  let canvas = createCanvas(650, 600);
  canvas.parent("canvas-wrapper");
  background(255);
}
function mouseDragged(){
  let type = _("#pen-pencil").checked?"pencil":"brush";
  let size = parseInt(_("#pen-size").value);
  let color = _("#pen-color").value;
  fill(color);
  stroke(color);
  if(type == "pencil"){
    line(pmouseX, pmouseY, mouseX, mouseY);
  } else {
    ellipse(mouseX, mouseY, size, size);
  }
}
_("#reset-canvas").addEventListener("click", function(){
  background(255);
});
_("#save-canvas").addEventListener("click",function(){
  saveCanvas(canvas, "sketch", "png");
});

Designing a Simple Quiz App using Svelte

In this article I will take you through how to design a simple Quiz app using svelte (HTML, CSS and JavaScript). For this, to write the questions of Quiz we will need JSON data in which we will be storing the question text, it's options and the correct option index. Below we have shown a sample JSON data.

JSON
[
   {
      "question":"Which of the following special symbol allowed in a variable name?",
      "options":[
         "* (asterisk)",
         "| (pipeline)",
         "- (hyphen)",
         "_ (underscore)"
      ],
      "correctIndex":3
   },
   {
      "question":"Which of the following correctly shows the hierarchy of arithmetic operations in C?",
      "options":[
         "/ + * -",
         "* - / +",
         "+ - / *",
         "/ * + -"
      ],
      "correctIndex":3
   },
   {
      "question":"Which header file should be included to use functions like malloc() and calloc()?",
      "options":[
         "memory.h",
         "stdlib.h",
         "string.h",
         "dos.h"
      ],
      "correctIndex":1
   },
   {
      "question":"Which bitwise operator is suitable for turning off a particular bit in a number?",
      "options":[
         "&& operator",
         "& operator",
         "|| operator",
         "! operator"
      ],
      "correctIndex":1
   },
   {
      "question":"What function should be used to free the memory allocated by calloc() ?",
      "options":[
         "dealloc();",
         "malloc(variable_name, 0)",
         "free();",
         "memalloc(variable_name, 0)"
      ],
      "correctIndex":2
   }
]
App.svelte
<script>
	let questions = [
		{
			"question": "Which of the following special symbol allowed in a variable name?",
			"options": [
				"* (asterisk)",
				"| (pipeline)",
				"- (hyphen)",
				"_ (underscore)"
			],
			"correctIndex": 3
		},
		{
			"question": "Which of the following correctly shows the hierarchy of arithmetic operations in C?",
			"options": [
				"/ + * -",
				"* - / +",
				"+ - / *",
				"/ * + -"
			],
			"correctIndex": 3
		},
		{
			"question": "Which header file should be included to use functions like malloc() and calloc()?",
			"options": [
				"memory.h",
				"stdlib.h",
				"string.h",
				"dos.h"
			],
			"correctIndex": 1
		},
		{
			"question": "Which bitwise operator is suitable for turning off a particular bit in a number?",
			"options": [
				"&& operator",
				"& operator",
				"|| operator",
				"! operator"
			],
			"correctIndex": 1
		},
		{
			"question": "What function should be used to free the memory allocated by calloc() ?",
			"options": [
				"dealloc();",
				"malloc(variable_name, 0)",
				"free();",
				"memalloc(variable_name, 0)"
			],
			"correctIndex": 2
		}
	];
	let answers = new Array(questions.length).fill(null);
	let questionPointer = -1;
	function getScore(){
		let score = answers.reduce((acc,val,index)=>{
			if(questions[index].correctIndex == val){
				return acc+1;
			}
			return acc;
		},0);
		return (score/questions.length * 100)+"%";
	}
	function restartQuiz(){
		answers = new Array(questions.length).fill(null);
		questionPointer = 0;
	}
</script>

<style>
	.app {
		position:absolute;
		top:0px;
		left:0px;
		width:100vw;
		height:100vh;
	}
	.app > div {
		width:100%;
		height:100%;
	}
	.app .start-screen,
	.app .score-screen{
		display:flex;
		justify-content:center;
		align-items:center;
	}
	.app .start-screen button,
	.app .score-screen button {
		padding:10px 20px;
		background:#4a77dc;
		color:#eee;
		border:none;
		outline:none;
		border-radius:20px;
		cursor:pointer;
	}
	.app .quiz-screen .main {
		padding:50px;
	}
	.app .quiz-screen .main .options {
		display:flex;
		justify-content:space-between;
		flex-wrap:wrap;
	}
	.app .quiz-screen .main .options button {
		width:45%;
		border-radius:20px;
		margin:10px 0px;
	}
	.app .quiz-screen .main .options button.selected {
		background:#111;
		color:#eee;
	}
	.app .quiz-screen .footer {
		position:fixed;
		bottom:0px;
		left:0px;
		width:100%;
		height:50px;
		display:flex;
		justify-content:space-between;
		align-items:center;
		background:#eee;
	}
	.app .quiz-screen .footer > div {
		margin:0px 10px;
	}
	.app .quiz-screen .footer .progress-bar {
		width:150px;
		height:10px;
		background:#aaa;
		border-radius:10px;
		overflow:hidden;
	}
	.app .quiz-screen .footer .progress-bar div {
		height:100%;
		background:#4a77dc;
	}
	.app .score-screen {
		flex-direction:column;
	} 
	.app .score-screen h1 {
		margin-bottom:10px;
	}
</style>

<div class="app">
	{#if questionPointer==-1}
		<div class="start-screen">
			<button on:click={()=>{questionPointer=0}}>
				Start Quiz
			</button>	
		</div>
	{:else if !(questionPointer > answers.length-1)}
		<div class="quiz-screen">
			<div class="main">
				<h2>
					{questions[questionPointer].question}
				</h2>
				<div class="options">
					{#each questions[questionPointer].options as opt,i}
						<button class="{answers[questionPointer]==i?'selected':''}" on:click={()=>{answers[questionPointer]=i}}>
							{opt}	
						</button>
					{/each}
				</div>
			</div>
			<div class="footer">
				<div class="progress-bar">
					<div style="width:{questionPointer/questions.length *100}%">
					</div>
				</div>
				<div class="buttons">
					<button disabled={questionPointer==0} on:click={()=>{questionPointer--}}>
						&lt;
					</button>
					<button on:click={()=>{questionPointer++}}>
						&gt;
					</button>
				</div>
			</div>
		</div>
	{:else}
		<div class="score-screen">
			<h1>
				Your score: {getScore()}
			</h1>
			<button on:click={restartQuiz}>
				Restart Quiz
			</button>
		</div>
	{/if}
</div>

Designing a Simple Calculator App using Svelte

Calculators are one of the beautifully designed app which provides easy and efficient way to perform mathematical function. This article talks about designing a calculator application using svelte.
 
<script>
	let total = 0;
	let console = "";
	let state = null;
	function resolveState(){
		switch(state){
			case "add":
				total += parseFloat(console);
				console = "0";
				break;
			case "substract":
				total -= parseFloat(console);
				console = "0";
				break;
			case "multiply":
				total *= parseFloat(console);
				console = "0";
				break;
			case "divide":
				total /= parseFloat(console);
				console = "0";
				break;
			default:
				total = parseFloat(console);
				console = "0";
				break;
		}
	}
	function setOperation(operation){
		resolveState();
		state = operation;
	}
	function setValue(value){
		if(console.toString() == "0" || state == "equal"){
			console = "";
		}
		if(state == "equal"){
			state = null;
		}
		if(value == "C"){
			total = 0;
			state = null;
			console = "";
			return;
		}
		console = console + value;
	}
	function equal(){
		resolveState();
		console = total;
		state = "equal";
	}
</script>

<style>
	.calculator {
		position:absolute;
		top:50%;
		left:50%;
		transform:translate(-50%,-50%);
		width:300px;
		border:1px solid #eee;
		box-shadow:2px 2px 2px #eee;
		padding:10px;
	}
	.calculator input {
		width:100%;
		padding:20px;
		outline:none;
		text-align:right;
		font-size:20px;
	}
	.calculator .buttons {
		display:flex;
		flex-wrap:wrap;
	}
	.calculator .buttons .operations {
		display:flex;
		justify-content:space-between;
		width:100%;
	}
	.calculator .buttons .operations button {
		width:24%;
	}
	.calculator .buttons .numbers {
		width:75%;
	}
	.calculator .buttons .numbers > div {
		display:flex;
		justify-content:space-between;
	}
	.calculator .buttons .numbers > div button {
		width:32%;
	}
	.calculator .equal {
		flex:1;
	}
	.calculator .equal button {
		margin-left:5%;
		width:95%;
		height:95%;
		background:#00acee;
		color:#eee;
	}
	.calculator button {
		outline:none;
	}
</style>

<div class="calculator">
	<input type="text" bind:value={console} readonly="true"/>
	<div class="buttons">
		<div class="operations">
			<button on:click={()=>{setOperation('add');}}>
				+
			</button>
			<button on:click={()=>{setOperation('substract');}}>
				-
			</button>
			<button on:click={()=>{setOperation('multiply');}}>
				&times;
			</button>
			<button on:click={()=>{setOperation('divide');}}>
				&divide;
			</button>
		</div>
		<div class="numbers">
			<div>
				<button on:click={()=>{setValue(7);}}>
					7
				</button>
				<button on:click={()=>{setValue(8);}}>
					8
				</button>
				<button on:click={()=>{setValue(9);}}>
					9
				</button>
			</div>
			<div>
				<button on:click={()=>{setValue(4);}}>
					4
				</button>
				<button on:click={()=>{setValue(5);}}>
					5
				</button>
				<button on:click={()=>{setValue(6);}}>
					6
				</button>
			</div>
			<div>
				<button on:click={()=>{setValue(1);}}>
					1
				</button>
				<button on:click={()=>{setValue(2);}}>
					2
				</button>
				<button on:click={()=>{setValue(3);}}>
					3
				</button>
			</div>
			<div>
				<button on:click={()=>{setValue(0);}}>
					0
				</button>
				<button on:click={()=>{setValue('.');}}>
					.
				</button>
				<button on:click={()=>{setValue('C');}}>
					C
				</button>
			</div>
		</div>
		<div class="equal">
			<button on:click={equal}>
				=
			</button>
		</div>
	</div>
</div>

Creating a Simple To-do App using Svelte

This article takes us through how we  can easily build / create simple and basic todo list app using svelte / HTML, CSS & JavaScript. By implementing todo list app we will understand if-else, each loop, event handling concepts of svelte.
<script>
let todos = []
let task = "";
	let filter='all';
	function addTask(){
		todos = [{
			task:task,
			status:"pending"
		}, ...todos];
		task = "";
	}
	function markComplete(i){
		todos[i].status = "completed";
		todos = [...todos];
	}
	function removeTask(i){
		todos.splice(i,1);
		todos = [...todos];
	}
</script>

<style>
	* {
		margin:0px;
		padding:0px
	}
	.container {
		width:100%;
		height:100vh;
		background:#1e85eb;
		display:flex;
		justify-content:center;
		align-items:center;
	}
	.todo {
		padding:20px;
		background:#f5f5f5;
		width:250px;
		border-radius:20px;
	}
	.todo > div {
		margin:20px 0px;
	}
	.todo .form{
		display:flex;
	}
	.todo .form input,
	.todo .form button {
		border:1px solid #1e85eb;
		height:40px;
		outline:none;
		border-radius:20px;
	}
	.todo .form input {
		flex:1;
		text-indent:20px;
	}
	.todo .form button {
		width:60px;
		margin-left:5px;
		color:#1e85eb;
		cursor:pointer;
	}
	.todo .tasks {
		min-height:100px;
	}
	.todo .tasks > .task {
		margin:10px 0px;
		display:flex;
	}
	.todo .tasks > .task > div {
		flex:1;
	}
	.todo .tasks > .task > button {
		width:25px;
		height:25px;
		border:1px solid #1e85eb;
		color:#1e85eb;
		border-radius:50%;
		margin:0px 5px;
		cursor:pointer;
	}
	.todo .tasks > .task > button.active{
		background:#1e85eb;
		color:#f5f5f5;
	}
	.todo .filters {
		display:flex;
		justify-content:space-between;
	}
	.todo .filters > button {
		padding:10px 8px;
		border:1px solid #1e85eb;
		color:#1e85eb;
		border-radius:20px;
		cursor:pointer;
	}
	.todo .filters > button.active {
		background:#1e85eb;
		color:#f5f5f5;
	}
</style>

<div class="container">
	<div class="todo">
		<div class="form">
			<input type="text" bind:value={task}/>
			<button on:click={addTask}>
				Add
			</button>
		</div>
		<div class="tasks">
			{#each todos as todo, i}
				{#if filter=='all'}
					<div class="task">
						<div>
							{todo.task}
						</div>
						<button class="{todo.status=='completed'?'active':''}" on:click={()=>{markComplete(i)}}>
							&#10004;
						</button>
						<button on:click={()=>{removeTask(i)}}>
							&#10006;
						</button>
					</div>
				{:else if filter=='completed'}
					{#if todo.status=='completed'}
						<div class="task">
							<div>
								{todo.task}
							</div>
							<button on:click={()=>{removeTask(i)}}>
								&#10006;
							</button>
						</div>
					{/if}
				{:else}
					{#if todo.status=='pending'}
						<div class="task">
							<div>
								{todo.task}
							</div>
							<button class="{todo.status=='completed'?'active':''}" on:click={()=>{markComplete(i)}}>
								&#10004;
							</button>
						</div>
					{/if}
				{/if}
			{/each}
		</div>
		<div class="filters">
			<button class="{filter=='all'?'active':''}" on:click={()=>{filter='all'}}>
				All
			</button>
			<button class="{filter=='completed'?'active':''}" on:click={()=>{filter='completed'}}>
				Completed
			</button>
			<button class="{filter=='incomplete'?'active':''}" on:click={()=>{filter='incomplete'}}>
				Incomplete
			</button>
		</div>
	</div>
</div>

Designing a Simple Sign-up Form using HTML, CSS & JavaScript

Here, we will see how to design a simple sign-up form using HTML, CSS and JavaScript. For this, initially we will create button on which we will attach "click"  event and then add signup form inside the popup. 

HTML
<div class="overlay-form">
  <div class="close-btn" onclick="toggleForm()">&times;</div>
  <h1>Create a new account</h1>
  <p>Join our community. Let's set up your account</p>
  <div class="form-element">
    <label for="fullname">Fullname</label>
    <input type="text" id="fullname">
  </div>
  <div class="form-element">
    <label for="email">Email</label>
    <input type="email" id="email">
  </div>
  <div class="form-element">
    <label for="password-1">Password</label>
    <input type="password" id="password-1">
  </div>
  <div class="form-element">
    <label for="password-2">Confirm password</label>
    <input type="password" id="password-2">
  </div>
  <div class="form-element">
    <button>Signup</button>
  </div>
</div>
<div class="center">
  <button onclick="toggleForm()">Signup</button>
</div>
CSS
body {
  margin:0px;
  font-family:"Open Sans",sans-serif;
  background:#ddd;
}
.overlay-form {
  position:absolute;
  top:50vh;
  left:0px;
  width:100vw;
  height:0vh;
  background:rgba(0,0,0,0.8);
  z-index:-1;
  opacity:0;
  padding:80px 100px;
  overflow:hidden;
  box-sizing:border-box;
  transition: top 500ms ease-in-out,
              opacity 500ms ease-in-out,
              height 0ms ease-in-out 500ms;  
}
.overlay-form .close-btn {
  position:absolute;
  top:20px;
  right:40px;
  color:#fff;
  font-size:40px;
  font-weight:600;
  cursor:pointer;
}
.overlay-form h1 {
  font-size:32px;
  color:#fff;
}
.overlay-form p {
  font-size:16px;
  color:#eee;
  margin:-15px 0px 30px;
}
.overlay-form .form-element {
  margin:20px 0px;
}
.overlay-form label {
  display:block;
  font-size:17px;
  color:#eee;
  margin-bottom:5px;
}
.overlay-form input {
  width:100%;
  padding:6px;
  font-size:17px;
  border:2px solid #eee;
  background:transparent;
  outline:none;
  border-radius:10px;
}
.overlay-form button,
.center button {
  margin-top:10px;
  width:100px;
  height:35px;
  font-size:15px;
  text-transform:uppercase;
  background:#fff;
  color:#222;
  border:none;
  outline:none;
  border-radius:10px;
}
.center {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
}
.center button {
  width:150px;
  height:40px;
  font-weight:600;
  box-shadow:3px 3px 2px 1px rgba(0,0,0,0.1);
  cursor:pointer;
}

body.activeForm .overlay-form {
  z-index:2;
  opacity:1;
  top:0px;
  height:100vh;
  transition: top 500ms ease-in-out,
              opacity 500ms ease-in-out,
              height 0ms ease-in-out 0ms;
}
JS
function toggleForm(){
  document.body.classList.toggle('activeForm');
}

Designing a Simple Google Image Search Box using HTML only

This article takes us through how we can add Google search bar to our website using HTML only. To implement this we will create a text box and assign "name" attribute as "q". Then we have created a GET request to "https://www.google.com/search" .

<form action="https://www.google.com/search">
  <input type="text" name="q">
  <input type="submit" value="search">
</form>

Creating Animated Popup / Modal Login Form Using HTML, CSS & JavaScript

In this post we will learn how to create animated popup / modal login form using HTML, CSS and JavaScript. For this, initially we will create button on which we will attach "click"  event and then add login form inside the popup.


HTML
<div class="center">
  <button onclick="openLoginForm()">Login</button>
</div>
<div class="popup-overlay"></div>
<div class="popup">
  <div class="popup-close" onclick="closeLoginForm()">&times;</div>
  <div class="form">
    <div class="avatar">
      <img src="https://bit.ly/31pHqJb" alt="">
    </div>
    <div class="header">
      Member login
    </div>
    <div class="element">
      <label for="username">Username</label>
      <input type="text" id="username">
    </div>
    <div class="element">
      <label for="password">Password</label>
      <input type="password" id="password">
    </div>
    <div class="element">
      <button>Login</button>
    </div>
  </div>
</div>
CSS
body {
  font-family:"Raleway";
}
.center {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
}
.popup-overlay {
  position:fixed;
  top:0px;
  left:0px;
  width:100%;
  height:100vh;
  z-index:1;
  background:rgba(0,0,0,0.5);
  display:none;
}
.popup {
  position:absolute;
  top:-150%;
  left:50%;
  transform:translate(-50%,-50%) scale(1.15);
  width:300px;
  height:440px;
  background:#f5f5f5;
  z-index:2;
  opacity:0;
  box-shadow:5px 5px 3px rgba(0,0,0,0.2);
  transition:transform 300ms ease-in-out,opacity 300ms ease-in-out;
}
body.showLoginForm .popup-overlay {
  display:block;
}
body.showLoginForm .popup {
  top:50%;
  opacity:1;
  transform:translate(-50%,-50%) scale(1);
}
.popup .popup-close {
  position:absolute;
  top:-10px;
  right:-10px;
  width:40px;
  height:40px;
  background:#555;
  color:#f5f5f5;
  font-size:25px;
  font-weight:600;
  text-align:center;
  border-radius:50%;
  cursor:pointer;
}
.popup .form .avatar {
  margin:30px 0px 20px;
  text-align:center;
}
.popup .form .avatar img {
  width:120px;
  border-radius:50%;
}
.popup .form .header {
  text-align:center;
  font-size:20px;
  font-weight:600;
  color:#222;
  margin:20px 0px;
}
.popup .form .element {
  padding:8px 20px;
}
.popup .form .element label {
  display:block;
  font-size:14px;
  color:#222;
  margin-bottom:5px;
}
.popup .form .element input {
  width:100%;
  padding:8px 10px;
  box-sizing:border-box;
  outline:none;
  border:1px solid #aaa;
  background:#eee;
  border-radius:5px;
}
.popup .form .element button {
  margin-top:5px;
  width:100%;
  padding:10px 0px;
  text-transform:uppercase;
  outline:none;
  border:none;
  font-size:15px;
  font-weight:600;
  border-radius:5px;
  cursor:pointer;
  background:#4889da;
  color:#f5f5f5;
}
JS
function openLoginForm(){
  document.body.classList.add("showLoginForm");
}
function closeLoginForm(){
  document.body.classList.remove("showLoginForm");
}

Design Sliding Sign-up & Sign-in Form using HTML, CSS & JavaScript

This article shows us about how we can design a sliding sign-up and sign-in form using HTML, CSS and JavaScript. 


HTML
<div class="form">
  <div class="back">
    <div>
      <h2>Don't have an account?</h2>
      <p>Sign up to save all your collections</p>
      <button id="show-signup-form">
        Sign up
      </button>
    </div>
    <div>
      <h2>Have an account?</h2>
      <p>Sign in to see all your collections</p>
      <button id="show-signin-form">
        Sign in
      </button>
    </div>
  </div>
  <div class="front">
    <div class="signin">
      <div class="title">
        Sign In
      </div>
      <div class="form-element">
        <i class="fa fa-envelope"></i>
        <input type="text" placeholder="Email">
      </div>
      <div class="form-element">
        <i class="fa fa-key"></i>
        <input type="password" placeholder="Password">
      </div>
      <div class="form-element">
        <button>Sign In</button>
      </div>
      <div class="form-element">
        <a href="#">Forgot password?</a>
      </div>
    </div>
    <div class="signup">
      <div class="title">
        Sign Up
      </div>
      <div class="form-element">
        <i class="fa fa-user"></i>
        <input type="text" placeholder="Fullname">
      </div>
      <div class="form-element">
        <i class="fa fa-envelope"></i>
        <input type="text" placeholder="Email">
      </div>
      <div class="form-element">
        <i class="fa fa-key"></i>
        <input type="password" placeholder="Password">
      </div>
      <div class="form-element">
        <button>Sign Up</button>
      </div>
    </div>
  </div>
</div>
CSS
body {
  background:#ccc;
  font-family:"Raleway";
}
.form {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  width:600px;
  height:350px;
}
.form .back {
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  width:100%;
  height:300px;
  background:#555;
  display:flex;
  justify-content:center;
  align-items:center;
  text-align:center;
}
.form .back > div {
  padding:30px;
  flex:1;
}
.form .back > div h2 {
  color:#f5f5f5;
}
.form .back > div p {
  color:#ccc;
}
.form .back > div button {
  padding:5px 10px;
  border:2px solid #f5f5f5;
  font-size:15px;
  font-weight:600;
  background:#555;
  color:#f5f5f5;
  border-radius:5px;
  cursor:pointer;
}
.form .front {
  position:relative;
  left:50%;
  width:50%;
  height:100%;
  background:#f5f5f5;
  transition:all 500ms ease-in-out;
}
.form .front .signup {
  display:none;
}
.form .front > div {
  padding:50px 20px;
  text-align:center;
}
.form .front .title {
  font-size:30px;
  font-weight:600;
  color:#555;
  margin-bottom:20px;
}
.form .front .form-element {
  position:relative;
  margin:15px 0px;
}
.form .front .form-element input {
  width:100%;
  padding:10px;
  font-size:16px;
  background:#ddd;
  border-radius:30px;
  border:none;
  outline:none;
  box-sizing:border-box;
  text-indent:35px;
}
.form .front .form-element i.fa {
  position:absolute;
  top:10px;
  left:15px;
  color:#555;
}
.form .front .form-element button {
  width:100%;
  padding:10px 0px;
  border-radius:30px;
  background:#00acee;
  color:#f5f5f5;
  border:none;
  outline:none;
  font-size:15px;
  font-weight:600;
  cursor:pointer;
}
.form .front .form-element a {
  text-decoration:none;
  color:#555;
  font-size:15px;
  font-weight:600;
} 
.form.active .front {
  left:0%;
}
.form.active .front .signup {
  display:block;
}
.form.active .front .signin {
  display:none;
}
JS
document.getElementById("show-signup-form").addEventListener("click",function(){
  document.getElementsByClassName("form")[0].classList.add("active");
});
document.getElementById("show-signin-form").addEventListener("click",function(){
  document.getElementsByClassName("form")[0].classList.remove("active");
});

Creating Custom Music Player App using HTML, CSS & JavaScript

This Post is about how to create a music player app using HTML , CSS and JavaScript. This music player app supports play/pause, forward/backward, seek bar, playlist etc.. You have to store music and thumbnail files in files directory and define JavaScript object which will stores information of song name, artist, its mp3 file and thumbnail file.
HTML
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
	<div class="player">
		<div class="main">
			<audio></audio>
			<div class="thumbnail">
				<img src="">
			</div>
			<div class="seekbar">
				<input type="range">
			</div>
			<div class="details">
				<h2></h2>
				<p></p>
			</div>
			<div class="controls">
				<div class="prev-control">
					<i class="fa fa-backward"></i>
				</div>
				<div class="play-pause-control paused">
					<i class="fa fa-play"></i>
					<i class="fa fa-pause"></i>
				</div>
				<div class="next-control">
					<i class="fa fa-forward"></i>
				</div>
			</div>
		</div>
		<div class="player-list">
			<div class="toggle-list">
				<i class="fa fa-angle-up"></i>
				<i class="fa fa-angle-down"></i>
			</div>
			<div class="list">
			</div>
		</div>
	</div>
	<script type="text/javascript" src="code.js"></script>
</body>
</html>
CSS
* {
	margin:0px;
	padding: 0px;
	box-sizing: border-box;
}
body {
	height: 100vh;
	font-family: "Raleway";
}
.player {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	width: 320px;
	height: 480px;
	overflow: hidden;
}
.player .main {
	width: 100%;
	height: 100%;
	background: #222;
	transition:all 500ms ease-in-out;
}
.player .main .thumbnail img {
	width: 100%;
}
.player .main .seekbar {
	margin-top: -15px;
}
.player .main .seekbar input[type="range"] {
	-webkit-appearance:none;
	width: 100%;
	height: 4px;
	outline: none;
	background: #aaa;
	overflow: hidden;
}
.player .main .seekbar input[type="range"]::-webkit-slider-thumb {
	-webkit-appearance:none;
	width: 0px;
	height: 0px;
	box-shadow: -300px 0px 0px 300px #00acee;
}
.player .main .details {
	text-align: center;
	padding: 15px 0px;
}
.player .main .details h2 {
	font-size: 18px;
	color:#eee;
	margin-bottom: 5px;
}
.player .main .details p {
	font-size: 15px;
	color: #aaa;
}
.player .main .controls {
	display: flex;
	justify-content: center;
	margin:8px 0px;
}
.player .main .controls > div {
	margin:0px 30px;
	cursor: pointer;
}
.player .main .controls i.fa {
	font-size:25px;
	color: #ddd;
}
.player .main .controls > div.play-pause-control i.fa-play {
	display: none;
}
.player .main .controls > div.play-pause-control.paused i.fa-play {
	display: block;
}
.player .main .controls > div.play-pause-control.paused i.fa-pause {
	display: none;
}
.player .player-list {
	position: absolute;
	width: 100%;
	margin-top:-20px;
	height: 350px;
	overflow-y: scroll;
	background: rgba(0,0,0,0.8);
	z-index:2;
	transition:all 500ms ease-in-out;
}
.player .player-list .toggle-list {
	position: sticky;
	top:0px;
	text-align: center;
	height: 20px;
	line-height: 20px;
	background: #555;
}
.player .player-list .toggle-list i.fa {
	color: #ccc;
	font-size: 20px;
	font-weight: 600;
}
.player .player-list .toggle-list i.fa-angle-down {
	display: none;
}
.player .player-list .toggle-list.active i.fa-angle-up {
	display: block;
}
.player .player-list .toggle-list.active i.fa-angle-down {
	display: none;
}
.player .list {
	padding: 10px;
}
.player .list .item {
	display: flex;
	padding: 5px 0px;
	border-bottom: 1px solid #222;
	cursor: pointer;
}
.player .list .item .thumbnail {
	width: 50px;
	height: 50px;
	overflow: hidden;
}
.player .list .thumbnail img {
	width: 100%;
	height: 100%;
}
.player .list .item .details {
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 0px 10px;
}
.player .list .item .details h2 {
	color: #eee;
	font-size: 16px;
}
.player .list .item .details p {
	color: #aaa;
	font-size: 15px;
}
.player .player-list::-webkit-scrollbar {
	width: 5px;
	background: #222;
}
.player .player-list::-webkit-scrollbar-thumb {
	background: #00acee;
}
.player.activeSongList .player-list {
	margin-top: -350px;
}
.player.activeSongList .main {
	filter:blur(5px);
}
JS
function _(query){
	return document.querySelector(query);
}
function _all(query){
	return document.querySelectorAll(query);
}
let songList = [
	{
		thumbnail:"Bright_Future.jpg",
		audio:"Bright_Future.mp3",
		songname:"Bright Future",
		artistname:"Silent Partner"
	},
	{
		thumbnail:"Bovi.jpg",
		audio:"Bovi.mp3",
		songname:"Bovi",
		artistname:"The Grand Affair",
	},
	{
		thumbnail:"Sunny_Looks_Good_on_You.jpg",
		audio:"Sunny_Looks_Good_on_You.mp3",
		songname:"Sunny Looks Good on You",
		artistname:"Midnight North",
	},
	{
		thumbnail:"Bright_Eyed_Blues.jpg",
		audio:"Bright_Eyed_Blues.mp3",
		songname:"Bright Eyed Blues",
		artistname:"Unicorn Heads",
	},
	{
		thumbnail:"How_it_Began.jpg",
		audio:"How_it_Began.mp3",
		songname:"How it Began",
		artistname:"Silent Partner",
	},
	{
		thumbnail:"Simon_s_Song.jpg",
		audio:"Simon_s_Song.mp3",
		songname:"Simon's Song",
		artistname:"Dan Lebowitz",
	},
	{
		thumbnail:"Scanline.jpg",
		audio:"Scanline.mp3",
		songname:"Scanline",
		artistname:"Mike Relm",
	},
	{
		thumbnail:"Flight_To_Tunisia.jpg",
		audio:"Flight_To_Tunisia.mp3",
		songname:"Flight To Tunisia",
		artistname:"Causmic",
	},
	{
		thumbnail:"Calimba.jpg",
		audio:"Calimba.mp3",
		songname:"Calimba",
		artistname:"E's Jammy Jams",
	},
	{
		thumbnail:"Everglow.jpg",
		audio:"Everglow.mp3",
		songname:"Everglow",
		artistname:"Patrick Patrikios",
	}
];

let currentSongIndex = 0;

let player = _(".player"),
	toggleSongList = _(".player .toggle-list");

let main = {
	audio:_(".player .main audio"),
	thumbnail:_(".player .main img"),
	seekbar:_(".player .main input"),
	songname:_(".player .main .details h2"),
	artistname:_(".player .main .details p"),
	prevControl:_(".player .main .controls .prev-control"),
	playPauseControl:_(".player .main .controls .play-pause-control"),
	nextControl:_(".player .main .controls .next-control")
}

toggleSongList.addEventListener("click", function(){
	toggleSongList.classList.toggle("active");
	player.classList.toggle("activeSongList");
});

_(".player .player-list .list").innerHTML = (songList.map(function(song,songIndex){
	return `
		<div class="item" songIndex="${songIndex}">
			<div class="thumbnail">
				<img src="./files/${song.thumbnail}">
			</div>
			<div class="details">
				<h2>${song.songname}</h2>
				<p>${song.artistname}</p>
			</div>
		</div>
	`;
}).join(""));

let songListItems = _all(".player .player-list .list .item");
for(let i=0;i<songListItems.length;i++){
	songListItems[i].addEventListener("click",function(){
		currentSongIndex = parseInt(songListItems[i].getAttribute("songIndex"));
		loadSong(currentSongIndex);
		player.classList.remove("activeSongList");
	});
}

function loadSong(songIndex){
	let song = songList[songIndex];
	main.thumbnail.setAttribute("src","./files/"+song.thumbnail);
	document.body.style.background = `linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.8)), url("./files/${song.thumbnail}") center no-repeat`;
	document.body.style.backgroundSize = "cover";	
	main.songname.innerText = song.songname;
	main.artistname.innerText = song.artistname;
	main.audio.setAttribute("src","./files/"+song.audio);
	main.seekbar.setAttribute("value",0);
	main.seekbar.setAttribute("min",0);
	main.seekbar.setAttribute("max",0);
	main.audio.addEventListener("canplay",function(){
		main.audio.play();
		if(!main.audio.paused){
			main.playPauseControl.classList.remove("paused");
		}
		main.seekbar.setAttribute("max",parseInt(main.audio.duration));
		main.audio.onended = function(){
			main.nextControl.click();
		}
	})
}
setInterval(function(){
	main.seekbar.value = parseInt(main.audio.currentTime);
},1000);

main.prevControl.addEventListener("click",function(){
	currentSongIndex--;
	if(currentSongIndex < 0){
		currentSongIndex = songList.length + currentSongIndex;
	}
	loadSong(currentSongIndex);
});
main.nextControl.addEventListener("click",function(){
	currentSongIndex = (currentSongIndex+1) % songList.length;
	loadSong(currentSongIndex);
});
main.playPauseControl.addEventListener("click",function(){
	if(main.audio.paused){
		main.playPauseControl.classList.remove("paused");
		main.audio.play();
	} else {
		main.playPauseControl.classList.add("paused");
		main.audio.pause();
	}
});
main.seekbar.addEventListener("change",function(){
	main.audio.currentTime = main.seekbar.value;
});
loadSong(currentSongIndex);

Create Instagram Profile Clone using Instagram API

Here, we are going to create Instagram profile clone using Svelte. To get Instagram profile data we have used Instagram open API (https://instagram.com/{username}?__a=1). Both the data about a particular profile and it's respective posts can be obtained using this data. "Profile.svelte" and "Posts.svelte" is implemented to show profile related data and the corresponding posts of a user respectively.


App.svelte
<script>
	import Profile from './Profile.svelte';
	import Posts from './Posts.svelte';
	let username = "";
	let INSTA = "https://instagram.com/";
	let user = null;
	let posts = null;
	async function searchUser(){
		let res = await fetch(INSTA+username+"?__a=1",{
			method:"GET"
		});
		let data = await res.json();
		console.log(data);
		user = data.graphql.user;
		posts = user.edge_owner_to_timeline_media.edges;
	}
</script>

<style>
	.header {
		padding:10px 0px;
		text-align:center;
		background:#111;
	}
</style>

<div class="header">
	<input type="text" bind:value={username}/>
	<button on:click={searchUser}>
		Search
	</button>
</div>
{#if user}
	<Profile {user}/>
	<Posts {posts} />
{/if}
Posts.svelte
<script>
	export let posts;
</script>

<style>
	.posts {
		margin-top:10px;
		display:flex;
		justify-content:space-between;
		flex-wrap:wrap;
	}
	.posts .post {
		width:48%;
	}
	.posts .post img {
		width:100%;
		height:220px;
		object-fit:cover;
	}
</style>

<div class="posts">
	{#each posts as post}
		<div class="post">
			<img src={post.node.display_url} alt="">	
		</div>
	{/each}
</div>
Profile.svelte
<script>
	export let user;
</script>

<style>
	.profile {
		padding:20px 50px;
		background:#eee;
		display:flex;
	}
	.profile * {
		margin:0px;
	}
	.profile .avatar {
		width:150px;
		text-align:center;
	}
	.profile .avatar img {
		width:120px;
		border-radius:50%;
	}
	.profile .info {
		flex:1;
		padding-left:10px;
	}
	.profile .info p {
		margin:10px 0px;
	}
	.profile .info .counts {
		display:flex;
	}
	.profile .info .counts > div {
		width:33.33%;
	}
</style>

<div class="profile">
	<div class="avatar">
		<img src={user.profile_pic_url_hd} alt="Profile Photo">
	</div>
	<div class="info">
		<h2>
			{user.full_name}
		</h2>
		<p>
			{user.biography}
		</p>
		<div class="counts">
			<div>
				<div>
					Followers
				</div>
				<div>
					{user.edge_followed_by.count}
				</div>
			</div>
			<div>
				<div>
					Following
				</div>
				<div>
					{user.edge_follow.count}
				</div>
			</div>
			<div>
				<div>
					Posts
				</div>
				<div>
					{user.edge_owner_to_timeline_media.count}
				</div>
			</div>
		</div>
	</div>
</div>

Design a Simple Sidebar using HTML, CSS & JavaScript

In this post we are going to see how we can design a simple sidebar using HTML, CSS and JavaScript. For this, initially we will create a hamburger menu and attach click event which will handle toggle (sidebar show/ hide) feature.


HTML
<div id="sidebar">
  <div class="toggle-btn" onclick="toggleSidebar(this)">
    <span></span>
    <span></span>
    <span></span>
  </div>  
  <div class="list">
    <div class="item">Home</div>
    <div class="item">About us</div>
    <div class="item">Contact us</div>
  </div>
</div>
CSS
* {
  margin:0px;
  padding:0px;
  box-sizing:border-box;
  font-family:sans-serif;
}

#sidebar {
  position:absolute;
  top:0px;
  left:-200px;
  width:200px;
  height:100%;
  background:#151719;
  transition:all 300ms linear;
}
#sidebar.active {
  left:0px;
}
#sidebar .toggle-btn {
  position:absolute;
  left:220px;
  top:10px;
}
#sidebar .toggle-btn span {
  display:block;
  width:30px;
  height:5px;
  background:#151719;
  margin:5px 0px;
  cursor:pointer;
}
#sidebar div.list div.item {
  padding:15px 10px;
  border-bottom:1px solid #444;
  color:#fcfcfc;
  text-transform:uppercase;
  font-size:15px;
}
JS
function toggleSidebar(ref){
  document.getElementById("sidebar").classList.toggle('active');
}

Building Popup / Modal using CSS Only

Popup boxes / Modal are useful way of showing an important information to the website visitors. In this post we will see how to create an animated popup box with close button using HTML and CSS only. Here we have used special CSS selectors ":target" to create toggle behaviour.

HTML
<div class="center">
  <a href="#popup">Open Popup</a>
</div>
<div id="popup">
  <div class="popup-content">
    <h1>This is title</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Itaque voluptatem dignissimos quis expedita earum explicabo nam perspiciatis. Aliquam, laudantium doloremque.</p>
    <a href="#" class="close-popup">&times;</a>
  </div>
</div>
CSS
body {
  margin:0px;
  height:100vh;
  font-family:"Open Sans",sans-serif;
  background:linear-gradient(to right, #00acee, #205172);
}
.center {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
}
.center a {
  padding:10px 20px;
  background:#eee;
  color:#111;
  font-size:15px;
  font-weight:600;
  text-decoration:none;
  border-radius:5px;
}
#popup {
  position:fixed;
  top:0px;
  left:0px;
  width:100vw;
  height:100vh;
  background:rgba(0,0,0,0.75);
  display:none;
}
#popup .popup-content {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  width:400px;
  padding:10px 20px;
  background:#eee;
}
#popup a.close-popup {
  position:absolute;
  top:20px;
  right:20px;
  font-size:20px;
  font-weight:600;
  text-decoration:none;
}
#popup:target {
  display:block;
}

Creating Sign-up and Login Form using HTML, CSS & JavaScript

This article takes us through how we can create a sign up + sign in form using HTML, CSS and JavaScript. There are two different tabs for Sign in and Sign up , whichever tab we will click on, the respective form will  be displayed.


HTML
<div class="form">
  <div class="tab-header">
    <div class="active">Sign Up</div>
    <div>Sign In</div>
  </div>
  <div class="tab-content">
    <div class="tab-body active">
      <div class="form-element">
        <input type="text" placeholder="Email">
      </div>
      <div class="form-element">
        <input type="text" placeholder="Username">
      </div>
      <div class="form-element">
        <input type="password" placeholder="Password">
      </div>
      <div class="form-element">
        <button>Sign Up</button>
      </div>
    </div>
    
    <div class="tab-body">
      <div class="form-element">
        <input type="text" placeholder="Email / Username">
      </div>
      <div class="form-element">
        <input type="password" placeholder="Password">
      </div>
      <div class="form-element">
        <input type="checkbox" id="remember_me">
        <label for="remember_me">Remember me</label>
      </div>
      <div class="form-element">
        <button>Sign In</button>
      </div>
    </div>
  </div>
</div>
CSS
* {
  box-sizing:border-box;
}
body {
  background:#ddd;
  font-family:"Raleway";
}
.form {
  position:absolute;
  top:50%;
  left:50%;
  transform:translate(-50%,-50%);
  width:300px;
  background:#f5f5f5;
  box-shadow:5px 5px 10px 5px #ccc;
}
.form .tab-header {
  height:50px;
  line-height:50px;
}
.form .tab-header > div {
  width:50%;
  float:left;
  text-align:center;
  background:#ddd;
  color:#555;
  cursor:pointer;
}
.form .tab-header > div.active {
  background:#f5f5f5;
  color:#111;
}
.form .tab-content {
  padding:20px;
}
.form .tab-content .form-element {
  margin:10px 0px;
}
.form .tab-content .form-element input {
  width:100%;
  padding:10px;
  border:1px solid #aaa;
  font-size:16px;
  background:#f5f5f5;
  border-radius:5px;
  outline:none;
}
.form .tab-content .form-element input[type="checkbox"] {
  width:30px;
  margin:8px 0px;
  margin-left:-5px;
}
.form .tab-content .form-element label {
  color:#111;
}
.form .tab-content .form-element button {
  margin-top:5px;
  width:100%;
  padding:10px;
  border:none;
  outline:none;
  background:#00acee;
  color:#f5f5f5;
  font-size:16px;
  text-transform:uppercase;
  cursor:pointer;
  border-radius:5px;
}
.form .tab-content > div.active {
  display:block;
}
.form .tab-content > div {
  display:none;
}
JS
let tabPanes = document.getElementsByClassName("tab-header")[0].getElementsByTagName("div");

for(let i=0;i<tabPanes.length;i++){
  tabPanes[i].addEventListener("click",function(){
    document.getElementsByClassName("tab-header")[0].getElementsByClassName("active")[0].classList.remove("active");
    tabPanes[i].classList.add("active");
    
    document.getElementsByClassName("tab-content")[0].getElementsByClassName("active")[0].classList.remove("active");
    document.getElementsByClassName("tab-content")[0].getElementsByClassName("tab-body")[i].classList.add("active");
  });
}