Simple Weight Converter using JavaScript (Code + Demo)

Weight Converter using JavaScript

In this article, I have shown you how to create a weight converter using JavaScript. JavaScript Weight Converter will help you to convert your weight to any other unit.

I have already shown you how to make a Height Converter. This project has been created with absolutely simple JavaScript. Here, if you input your weight in kg, it will be converted into pounds. Here I have arranged to convert from kg to pound. But you can convert any unit if you want. I have shown below how to do it.

There is an input box here. You can input weight in that box. There is a button, when you click on the button you will see the weight in pounds.

JavaScript Weight Converter

Although I made this JavaScript Weight Converter here in a pound unit. You can use any other unit here.

Here is a step-by-step tutorial, with the required source code and live preview. As a result, you will not have any difficulty. But yes you need to have some idea about HTML, CSS, and JavaScript.

For your convenience, I have given a preview below. This will help you to know how Weight Converter JavaScript works.

See the Pen
Untitled
by Shantanu Jana (@shantanu-jana)
on CodePen.

Hope you found out by looking at the preview above. First created a small box on the webpage. I used yellow as the background and added a white shadow all around. 

First, there is a heading, then an input box. In the input box, you will input your weight in kg. Then there is a submit button. At the end of all, there is a display in which the result can be seen.

How to Create a Weight Converter in JavaScript

Now below I have shared a step-by-step tutorial. If you are a beginner, follow these steps. If you want source code, use the download button directly below.

Step 1: HTML code of Weight Converter

Javascript weight converter information has been added using the following HTML codes. Here’s all the HTML code I’ve put together. 

First, a basic structure has been created. Then a heading, two input boxes, and a result viewing area.

<div class=”container”>
  <form action=””>
     <h1>Weight Convertor</h1>
     <label for=”weight-converter”>KG : </label>
     <input type=”text” step=”5″ placeholder=”Enter your weight in Kg”/>
     <input type=”submit” id=”enter-btn” value=”Enter”>
     <p>Your weight in POUNDS is : <span id=”convertedWeight”></span></p>
  </form>
</div>

Step 2: Basic Design of Weight Converter

Using some of the CSS code below I designed the webpage and added a background color here. The dark blue color is used in the background.

* {
box-sizing: border-box;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
text-align: center;
font-family: “Poppins”, sans-serif;
background: #0462a4;
}
HTML code of Weight Converter

Now the basic structure of this weight converter has been designed. This box is width: 400px, the background color is yellow and a white shadow is used all around.

.container {
background: #ede574; 
border-radius: 7px;
width: 400px;
padding: 0.5rem 2rem 2rem 2rem;
box-shadow: 0px 0px 10px #bebebe;
}
Basic Design of Weight Converter

Step 3: Design input boxes and buttons (more…)

Continue ReadingSimple Weight Converter using JavaScript (Code + Demo)

Animated Eyes Follow Mouse Cursor in JavaScript

JavaScript Eyes Follow Mouse Effect

In this article, you will learn how to create Animated Eyes Follow Mouse. Simple HTML CSS JavaScript is used here. Animation plays an important role in making a webpage attractive. Javascript eyes follow mouse effect has been created here. 

Earlier I shared a CSS follow mouse tutorial. But it is a bit different. Two eyes have been made here. Those two eyes will follow your mouse cursor. Here the eye will be in the same place but the eyepoint will change position.

JavaScript Eyes Follow Mouse Effect

To create this Eyes Follow Mouse Cursor design, some CSS and some JavaScript have been used. But to design it, you must have some idea about JavaScript. This type of animation can be used with any type of web element or logo.

I have given a demo below for your convenience. Here you will see a live preview of this Animated Eyes Follow. From here you can copy all the code directly.

See the Pen
Untitled
by Shantanu Jana (@shantanu-jana)
on CodePen.

Two circles have been drawn on the dense blue webpage. That circle is designed in such a way that it looks like an eye. 

Small circles have been created in those circles which will act as eyeballs. This eyeball will follow your mouse cursor when you change the position of the mouse cursor.

Animated Eyes Follow Mouse Cursor in JavaScript

In this tutorial, I have shared step by step tutorial and source code. If you only want the source code, you can use the download button below the article. But if you are a beginner, you must follow the step-by-step tutorial below.

Step 1: Basic structure of Eyes Follow

I have created more structures and eyes for this project using the following HTML code.

<div class=”container”>
    <div class=”eyes”></div>
    <div class=”eyes”></div>
</div>

Now I have designed the web page using some amount of CSS. Here are some simple designs and use a deep blue background color on the web page.

* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: “Bebas Neue”, cursive;
background: #0c3b5a;  
 }
Basic structure of Eyes Follow

Step 2: Design the Eyes Follow Cursor (more…)

Continue ReadingAnimated Eyes Follow Mouse Cursor in JavaScript

How to Create a Digital Clock in JavaScript

JavaScript Digital Clock

If you want to create a Simple Digital Clock using JavaScript then this tutorial is for you. There are many types of digital clock tutorials available on the Internet. However, this design is made in the easiest way. 

I used only three lines of JavaScript to create this simple digital clock. I have already created many types of JavaScript clocks. If you want to create an advanced and stylish digital clock then you can search this blog.

 However, there are many beginners who want a very simple design. This simple JavaScript digital clock tutorial would be perfect for them. Here I have given step by step tutorial and required source code.

JavaScript Digital Clock

If you want to know how Working Digital Clockworks then be sure to follow the demo section below. Here you will find the required preview and source code.

See the Pen
Untitled
by Shantanu Jana (@shantanu-jana)
on CodePen.

As you can see, I have created a box on top of a web page. In this box, first, you can see the time, then you can see a text. During this time you will see the time in hours, minutes, and seconds. 

It has AM and PM options. I have already created a digital clock with the date. If you need to show the date with your time, you can see that design.

Create a digital clock using Javascript

Some HTML, some CSS, and 3-line JavaScript have been used for designing. The current time has been taken from your device using the newDate () method. newDate () is a JavaScript method that will take the current time from your device.

1: Basic structure of the clock

First, a box is created using the following HTML CSS. In this box, you can see all the information related to time.

<div class=”container”>
</div>

I designed the webpage with the code below and then designed the box. This box has no specific width height. This will determine the amount of content and the size of the padding.

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
text-align: center;
background-color: #08798c;
font-family: sans-serif;
}
.container {
border-radius: 10px;
background: #f7f9f7;
box-shadow: 0px 0px 20px #282d28;
padding: 2rem 3rem 3rem 3rem;
color: #191414;
cursor: default;
}
Basic structure of the clock

2: Create time viewing area (more…)

Continue ReadingHow to Create a Digital Clock in JavaScript

Simple Social Media Icons Hover Effect with CSS

Social Media Icons hover effect

This is a CSS tutorial where you will learn how to create simple social media icons with a hover effect. The hover or animation effect makes the social button much more interesting. Here a few CSS social buttons have been created and hover colors have been used in them.

Social icons are a common element among different websites or projects. The social media buttons that have been created here use animated hover colors.

Social Media Icons hover effect

This social icon hovers effect is made using only HTML and CSS you can use anywhere. I have added icons using HTML. These social icons have been designed and hovered using CSS.

See the Pen
Social Icon Hover Effect
by Shantanu Jana (@shantanu-jana)
on CodePen.

This is a complete tutorial where you can get all the source code, step-by-step tutorials, and live previews. So if you are a beginner then this tutorial will help you a lot. If you want to see the preview then use the demo section above.

Create a Social Media Buttons with CSS

Here five hover effect social icons are used and they are given in the form of a round button. 

Now if you want to make it, you need to have some idea about HTML and CSS. If you are not technical then use the download button directly below the article.

Step 1: HTML code of Social Icons

All social icons have been added by the following HTML code. Here I have used 5 social icons.

<div class=”social-icons”>
   <a class=”social-icon twitter” href=”#”>
      <i class=”fab fa-twitter”></i>
   </a>
   <a class=”social-icon dribbble” href=”#”>
      <i class=”fab fa-dribbble”></i>
   </a>
   <a class=”social-icon facebook” href=”#”>
      <i class=”fab fa-facebook-f”></i>
   </a>
   <a class=”social-icon instagram” href=”#”>
      <i class=”fab fa-instagram”></i>
   </a>
   <a class=”social-icon github” href=”#”>
      <i class=”fab fa-github”></i>
   </a>
</div>

Step 2: Basic design of webpage by CSS (more…)

Continue ReadingSimple Social Media Icons Hover Effect with CSS

Draggable Div Element using JavaScript (Code + Demo)

draggable div javascript

In this article, you will learn how to create javascript draggable div. What is Draggable Div Element?

Basically, it is an element that you can drag anywhere on the web page. We see this kind of draggable element in many large websites or applications.

Elements that can be dragged from one place to another are called javascript draggable div. In the meantime, I have shared how to create a right-click menu using JavaScript.

I have added a profile card to the basic structure of this draggable div javascript. However, you can add any of your information by excluding the profile card.

Draggable Div JavaScript

When we see this type of element in an application, it seems to be a lot standard. However, it is not so difficult. If you want, you can create this kind of Drag and Drop element using some basic HTML CSS and JavaScript.

If you have difficulty understanding what I am saying then follow the preview below. Here you will find a live preview of this Draggable Div Element design and the required source code.

See the Pen
Untitled
by Foolish Developer (@foolishdevweb)
on CodePen.

As you can see above, I designed a web page. I made a small box on it. Under normal conditions, this box will be in top: 0 and left: 0 positions. 

You can then move it to the angle and position of your choice. I have created a profile card in this element. For the profile, first, we added the profile image, some basic text, and four social media buttons.

How to create draggable div in javascript

Although this profile is not part of the Drag element. I just added the card to add some information. Shared step-by-step tutorials here. For this, you must have some idea about HTML CSS JavaScript.

Step 1: Basic structure of draggable div

First I created the basic structure of the Drag element. Here you can create using a single div if you want. But I have used a div and a header here. 

Div is basically the basic structure and the header is the part where you can drag by clicking. Although the length of the header here is equal to the size of the whole box. So you can move Div Element by clicking on any part of the box.

<div id=”dragable”>
   <header id=”dragzone”>
   </header>
</div>

I have designed the webpage of this project using the following CSS codes. Here a blue color is used in the background of the webpage.

* {
margin: 0;
padding: 0;
border: none;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body {
height: 100%;
}
body {
background: #78c7ed;
font-family: sans-serif;
}
Basic structure of draggable div

Step 2: Basic design of Div Element

Now the basic structure of the element or the box has been created. Box width: 21rem, height: 21rem, and a light border has been used all around. Shadow has been used here to enhance the beauty.

#dragable {
width: 21rem;
height: 21rem;
border: 0.2rem solid #0f2c65;
border-radius: 0.2rem;
position: absolute;
z-index: 9;
box-shadow: 2px 4px 18px rgba(0, 0, 0, 0.2);
transition: border-color 0.2s, box-shadow 0.2s;
}

Now we will design the header. This is basically where we can click and move the JavaScript Draggable Div Element. Here I have used 100% of the length and height. 

This will allow you to move it by clicking anywhere in the entire box. Cursor: move is used here, so moving the mouse over the box will change the style of the cursor.

#dragable #dragzone {
width: 100%;
height: 100%;
cursor: move;
z-index: 10;
background-color: #0f2c65;
}
Basic design of Div Element

When you click on the box or move it, the style changes a bit. Although it will not work without JavaScript.

#dragable.drag {
border-color: white;
box-shadow: 3px 6px 24px rgba(0, 0, 0, 0.5);
}

Step 3: Activate Draggable Div using JavaScript

Now it’s time to implement this HTML Drag and Drop via JavaScript. It is comparatively much harder. For this, you must have an idea about JavaScript. 

Here we have shared the necessary explanations of the code lines. Hopefully, these codes will not be a problem for you to understand.

 const dragElement = (element, dragzone) => {
    let pos1 = 0,
      pos2 = 0,
      pos3 = 0,
      pos4 = 0;
//MouseUp occurs when the user releases the mouse button
    const dragMouseUp = () => {
      document.onmouseup = null;
//onmousemove attribute fires when the pointer is moving while it is over an element.
      document.onmousemove = null;
      element.classList.remove(“drag”);
    };
    const dragMouseMove = (event) => {
//preventDefault() method cancels the event if it is cancelable
      event.preventDefault();
//clientX property returns the horizontal coordinate of the mouse pointer
      pos1 = pos3 – event.clientX;
//clientY property returns the vertical coordinate of the mouse pointer
      pos2 = pos4 – event.clientY;
      pos3 = event.clientX;
      pos4 = event.clientY;
//offsetTop property returns the top position relative to the parent
      element.style.top = `${element.offsetTop – pos2}px`;
      element.style.left = `${element.offsetLeft – pos1}px`;
    };
    const dragMouseDown = (event) => {
      event.preventDefault();
      pos3 = event.clientX;
      pos4 = event.clientY;
      element.classList.add(“drag”);
      document.onmouseup = dragMouseUp;
      document.onmousemove = dragMouseMove;
    };
    dragzone.onmousedown = dragMouseDown;
  };
  const dragable = document.getElementById(“dragable”),
    dragzone = document.getElementById(“dragzone”);
  dragElement(dragable, dragzone);
Draggable Div using JavaScript

To make this div element draggable complete the work above. Now you can move this element anywhere.

 You can add any information here. Here I have added a profile card. If you want to add a profile card to that draggable element then follow the steps below. Otherwise, skip the steps.

Step 4: Add content to Draggable Element (more…)

Continue ReadingDraggable Div Element using JavaScript (Code + Demo)

How To Create Custom Radio Button Using HTML CSS

Custom Radio Button CSS

If you want to create Custom Radio Button using HTML and CSS then this tutorial will help you completely. customize radio buttons is a common web element that is used in many different places. The input of HTML is created using type = “radio”.

 However, ordinary radio buttons cannot be used everywhere. This radio button needs to be styled to be used for various purposes. Here is a simple radio button using some CSS to make it suitable for interesting and professional use.

Custom Radio Button CSS

3 Radio buttons have been used here. These Custom Radio Buttons are made in the form of small boxes.

Many times one has to choose any one of the many options on the webpage. In that case, there is no alternative to this kind of CSS Radio Button.

See the Pen
Untitled
by Shantanu Jana (@shantanu-jana)
on CodePen.

This tutorial will help you to know how to style a radio button. It is designed to be used for a professional purpose. Above is a demo that will help you figure out how it works. Here you will find the required source code and tutorials.

How to Customize radio buttons in CSS

As you can see, three boxes have been created on the webpage. Those boxes are basically radio buttons. You can select these radio buttons. By default, the middle option will be selected. 

You can also select any other option of your choice by clicking on it. It’s a little easier to build with a little bit of HTML and CSS used.

Step 1: Radio Button’s HTML code

below I put all the HTML codes together. Later I designed them with CSS. These select buttons are made in the shape of a box. This box contains some basic information.

<div class=”card”>
  <input type=”radio” name=”pricing” id=”card1″>
  <label for=”card1″>
     <h5>BASIC</h5>
     <h2>
       <span>$</span>
        15
       <span>/month</span>
    </h2>
  </label>
</div>
<div class=”card”>
   <input type=”radio” name=”pricing” id=”card2″ checked>
   <label for=”card2″>
      <h5>STANDARD</h5>
      <h2>
         <span>$</span>
          35
         <span>/month</span>
      </h2>
    </label>
</div>
<div class=”card”>
   <input type=”radio” name=”pricing” id=”card3″>
   <label for=”card3″>
      <h5>PREMIUM</h5>
      <h2>
        <span>$</span>
          120
        <span>/month</span>
      </h2>
  </label>
</div>
Radio Button's HTML code

Step 2: Design webpages with CSS

I designed the webpage using the following code. Light blue is used in the background of the webpage here.

*,
*:before,
*:after{
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
body{
  background-color: #f5f7ff;
  font-family: ‘Poppins’,sans-serif;
  color: #2c2c51;
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: space-around;
}
Design webpages with CSS

Step 3: Customize the Radio Button (more…)

Continue ReadingHow To Create Custom Radio Button Using HTML CSS