<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anand Vijay</title>
    <description>The latest articles on DEV Community by Anand Vijay (@anandson47).</description>
    <link>https://dev.to/anandson47</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F456615%2F93f04c88-a01f-4d84-9d66-222f5aa96d71.png</url>
      <title>DEV Community: Anand Vijay</title>
      <link>https://dev.to/anandson47</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anandson47"/>
    <language>en</language>
    <item>
      <title>How to build a custom input range slider</title>
      <dc:creator>Anand Vijay</dc:creator>
      <pubDate>Sat, 28 Oct 2023 10:32:07 +0000</pubDate>
      <link>https://dev.to/anandson47/how-to-build-a-custom-input-range-slider-4d59</link>
      <guid>https://dev.to/anandson47/how-to-build-a-custom-input-range-slider-4d59</guid>
      <description>&lt;h2&gt;
  
  
  1. Introduction
&lt;/h2&gt;

&lt;p&gt;Today we are going to build a customised input range slider. In HTML we have an input tag that has many types. One of those types is &lt;code&gt;range&lt;/code&gt;. Now although it is a useful accessory, often we struggle to get it to match with the rest of our UI. So lets get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. HTML
&lt;/h2&gt;

&lt;p&gt;So for the layout of the slider lets have two buttons that add and subtract value from the range and obviously the slider itself in between.&lt;/p&gt;

&lt;p&gt;Now add this to your HTML file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="range"&amp;gt;
  &amp;lt;div class="rangeAction"&amp;gt;-&amp;lt;/div&amp;gt;
  &amp;lt;input type="range" class="slider" min="0" max="100" value="0"&amp;gt;
  &amp;lt;div class="rangeAction"&amp;gt;+&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the HTML above, we have a parent &lt;code&gt;div&lt;/code&gt; element that contains all the elements of the slider. Within that container we have two action containers with the plus and minus sign as their text content. And finally we also have the &lt;code&gt;input&lt;/code&gt; tag with the following attributes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;type : Denotes the type of the input (In this case ,range)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;min: Minimum value of the slider&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;max: Maximum value of the slider&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;value: Initial value of the slider&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. CSS
&lt;/h2&gt;

&lt;p&gt;Now the most important and interesting part of this article, the CSS. Now let give a base style to the parent container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.range{
  display:flex;
  justify-content:"center";
  align-items:"center";
  height:100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets add styling to the action containers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.rangeAction{
  background-color:white;
  width:50px;
  height:50px;
  cursor:pointer;
  display:flex;
  justify-content:center;
  align-items:center;
  border-radius:50%;
  border:1px solid #c2c2c2
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the action containers are ready , let us move on to the slider. First we'll give the slider some base styles and then style the range indicator. So for the slider give it the following styles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.slider {
  -webkit-appearance: none;
  width: 90%;
  margin-left:20px;
  margin-right:20px;
  height: 10px;
  border-radius:50px;
  background: #d3d3d3;
  margin-top:40px;
  outline: none;
  opacity: 0.7;
  -webkit-transition: .2s;
  transition: opacity .2s;
}

.slider:hover {
  opacity: 1;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now to adjust the range indicator we will apply styles to it using the &lt;code&gt;::-webkit-slider-thumb&lt;/code&gt; selector added to our &lt;code&gt;.slider&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 75px;
  height: 75px;
  background: white;
  border:10px solid blue;
  cursor: pointer;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the styling is complete lets add the relevant functionality to the plus and minus buttons.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. JavaScript
&lt;/h2&gt;

&lt;p&gt;First we need select the buttons and the slider using DOM&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let actionButtons=document.getElementsByClassName("rangeAction")
let minus=actionButtons[0]
let plus=actionButtons[1]
let slider=document.querySelector("[type=range]")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that all the required elements are selected lets add &lt;code&gt;onclick&lt;/code&gt; events to the plus and minus buttons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minus.onclick=function(e){
  slider.value=parseInt(slider.value)-5
}

plus.onclick=function(e){
    slider.value=parseInt(slider.value)+5
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I have provided a value change of 5. You can change that according to you requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Result
&lt;/h2&gt;

&lt;p&gt;Now you should have an input range slider that looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iA81a7dJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9xs7pcfp02oejts6st0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iA81a7dJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9xs7pcfp02oejts6st0.png" alt="Image description" width="800" height="38"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations, you have now successfully learnt to create a custom range slider.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Lets talk about A-Frame</title>
      <dc:creator>Anand Vijay</dc:creator>
      <pubDate>Sat, 21 Oct 2023 13:27:32 +0000</pubDate>
      <link>https://dev.to/anandson47/lets-talk-about-a-frame-2n3d</link>
      <guid>https://dev.to/anandson47/lets-talk-about-a-frame-2n3d</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A-Frame is essentially a web framework that can be used to create a VR experience on top of your HTML. How cool is that? A-Frame is compatible with most VR headsets including the GearVR and Oculus Go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why A-Frame?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Easy Setup&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A-Frame handles all the boilerplate setup to create the 3D experience for you. All you have to do to begin is create an HTML file , add a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag with the A-Frame CDN and then drop &lt;code&gt;&amp;lt;a-scene&amp;gt;&lt;/code&gt; tag and voila. Your initial VR scene is ready.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Its like coding in HTML&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So A-Frame follows a concept of declarative HTML and since HTML is easy to read and understand , A-Frame is accessible to everyone.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Works on multiple devices&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now A-frame like mentioned earlier works on most VR headsets but you also have the comfort of using them on a normal desktop or even a smartphone.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Entity Component Architecture&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While we code on top of HTML that is just one cool feature. The developer simultaneously has access to Javascript , DOM , Three.js , WebVR and WebGL.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Visual Inspector&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now as a front end developer myself I highly appreciate the use of developer tools to allow me to inspect elements. A-Frame provides a Visual Inspector of its own that allows us to view/inspect the various aspects of the scene. We can open the scene using &lt;code&gt;&amp;lt;ctrl&amp;gt; + &amp;lt;alt&amp;gt; + i&lt;/code&gt; or &lt;code&gt;&amp;lt;ctrl&amp;gt; + &amp;lt;option&amp;gt; + i&lt;/code&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Lets build our first Scene
&lt;/h2&gt;

&lt;p&gt;Now lets create our first VR scene on A-Frame.&lt;/p&gt;

&lt;p&gt;Create an HTML file the following structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;

    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;

    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag add the A-Frame CDN&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://aframe.io/releases/1.4.0/aframe.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside your body tag add an &lt;code&gt;&amp;lt;a-scene&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;Now that the initial setup is done we can start by adding elements to the scene.&lt;/p&gt;

&lt;p&gt;Now we need to create an assets section using the &lt;code&gt;&amp;lt;a-assets&amp;gt;&lt;/code&gt;. Inside the &lt;code&gt;a-assets&lt;/code&gt; section is where we add all our assets like images and videos. Remember to provide each asset with an &lt;code&gt;id&lt;/code&gt; attribute as we use this ID to point to the asset wherever we require it.&lt;/p&gt;

&lt;p&gt;So lets begin with a background image . Let's add a random panoramic Image I found online with the &lt;code&gt;id="background"&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Now let's add an a-sky element with src pointing to this image like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a-sky src="#background"&amp;gt;&amp;lt;/a-sky&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now once you run the html file your Vr scene should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t7LWJhw7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6pnd2i9b51103145kvx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t7LWJhw7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6pnd2i9b51103145kvx4.png" alt="Image description" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and your code will look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;script src="https://aframe.io/releases/1.4.0/aframe.min.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;a-scene&amp;gt;
            &amp;lt;a-assets&amp;gt;
                &amp;lt;img src="./background.jpg" id="background"/&amp;gt;
            &amp;lt;/a-assets&amp;gt;
            &amp;lt;a-sky src="#background"&amp;gt;&amp;lt;/a-sky&amp;gt;
        &amp;lt;/a-scene&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets add some shapes to the Scene. A-Frame provides use with some primitive elements to use in the scene. For now lets add a box and a sphere. Add the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"&amp;gt;&amp;lt;/a-box&amp;gt;
&amp;lt;a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"&amp;gt;&amp;lt;/a-sphere&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The position attribute determines the position of the element in the scene using x-y-z coordinates.&lt;/p&gt;

&lt;p&gt;Now your scene should look like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mkaGqkXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ev7e1c8j50ql360dk54f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mkaGqkXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ev7e1c8j50ql360dk54f.png" alt="Image description" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And your final code should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;script src="https://aframe.io/releases/1.4.0/aframe.min.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;a-scene&amp;gt;
            &amp;lt;a-assets&amp;gt;
                &amp;lt;img src="./background.jpg" id="background"/&amp;gt;
            &amp;lt;/a-assets&amp;gt;
            &amp;lt;a-sky src="#background"&amp;gt;&amp;lt;/a-sky&amp;gt;
            &amp;lt;a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"&amp;gt;&amp;lt;/a-box&amp;gt;
      &amp;lt;a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"&amp;gt;&amp;lt;/a-sphere&amp;gt; 

        &amp;lt;/a-scene&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You have successfully created your first scene using A-Frame.&lt;br&gt;
I hope this articles helps more front-end developers like me understand how easily a VR scene can be created. Thank You.&lt;/p&gt;

</description>
      <category>vr</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
