Showing posts with label Bootstrap. Show all posts
Showing posts with label Bootstrap. Show all posts

Color Picker

Hi friends, In this post you will learn how to create a color picker tool with pure JavaScript. In this tool we will create a color palette dynamically with our defined custom colors and simply destroy it after selection of color. We will use the bootstrap framework for styling the tool. Let's do this:

Live example: https://jsfiddle.net/trickyui/4hm2wyep/

First of all you have to add bootstrap and google material icons libraries locally or through CDN.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

HTML

<div class="input-group">
     <input type="text" class="form-control">
     <div class="input-group-addon color-palette" data-id="colors">
         <i class="material-icons" data-id="cat_color">lens</i>
     </div>
</div>

CSS
For styling the tool you have to add some CSS for styling the tool:

.color-palette{
     position: relative;
}
 .color-palette .color-box {
     position: absolute;
     padding: 6px;
     right: 0px;
     top: 100%;
     z-index: 9;
     min-width: 270px;
     -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
     -moz-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
     -ms-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
     -o-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
     box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
     background-color: #ffffff;
     border-radius: 4px;
     border: 1px solid #f5f5f5;
}
 .color-palette .color-box > div {
     float: left;
     width: 30px;
     height: 30px;
     border: 3px solid #ffffff;
     border-radius: 50%;
     margin: 6px;
}


JavaScript

// Colors
var colors = ['#ef4438', '#e71f63', '#8f4098', '#65499d', '#4555a5', '#478fcc', '#38a3dc', '#0abbd3', '#009688', '#4dae4c', '#8ac147', '#cddc35', '#fde937', '#fbc015', '#f8981f', '#f0592b', '#afbdc4', '#607d8b', '#bdaaa4', '#795649', '#eeeded', '#9d9d9d', '#616161', '#202020'];

var elements = document.querySelectorAll('[data-id="cat_color"]');
elements.forEach(function (e) {
   e.addEventListener('click', function (ev) {
      if (document.querySelectorAll('.color-box').length >= 0) {
         document.querySelectorAll('.color-box').forEach(function (e) {
              e.remove();
         });
         var node = document.createElement("DIV");
         node.setAttribute('class', 'color-box');
         node.setAttribute('id', 'color_box');
         for (i = 0; i < colors.length; i++) {
             var item = document.createElement('DIV');
             item.setAttribute('class', 'color');
             item.setAttribute('style', 'background-color:' + colors[i]);
             item.setAttribute('onclick', 'setColor(this)');
             node.appendChild(item);
         }
         e.parentNode.appendChild(node);
      }
   });
});

// select the color from palette
function setColor(color) {
       color.parentNode.previousElementSibling.style.color = color.style.backgroundColor;
}

// remove the palette on document click
window.onload = function () {
   document.onclick = function (e) {
       var elem = document.getElementById('color_box');
       if (elem) {
           if (e.target.dataset.id !== 'cat_color' && e.target.id !== 'color_box') {
             document.getElementById('color_box').remove();
           }
       }
   }
}

For live example please go to this link: Live example: https://jsfiddle.net/trickyui/4hm2wyep/

Speed test meter with CSS and Jquery



Hi friends, in this tutorial you will learn how to create a speed test meter (speedometer) with pure CSS and Jquery animations. A speedometer works on the basis of speed and angle calculations. So, in this tutorial we will calculate the angle of a meter pointer and animate it.

Live demo: https://jsfiddle.net/trickyui/jwj52wmh/

HTML: 

In this example, we used "bootstrap.min.css" (Bootstrap 4) for design and style the meter. You can follow us or create your own design and style.

1. First of all we created a meter.










2.  Set pointers inside the meter.








3. Set a needle inside the meter for showing the speed.



<div class="box"> <h2 class="mb-4 text-center">Speedometer</h2> <div class="meter position-relative"> <img src="assets/images/meter-bg.png" alt="" class="img-fluid"> <span class="num" id="num_1"></span> <span class="num" id="num_2"></span> <span class="num" id="num_3"></span> <span class="num" id="num_4"></span> <span class="num" id="num_5"></span> <span class="num" id="num_6"></span> <span class="num" id="num_7"></span> <img src="assets/images/meter-hand.png" alt="" class="meter-hand" id="hand"> </div> <div class="text-center mt-2"> <div class="speed"><span id="speed">53.2</span></div> <div class="unit">MBPS</div> </div> </div>


CSS:
html { font-size: 10px; } body { font-family: 'Montserrat', sans-serif; font-size: 1.4rem; line-height: 1.4; font-weight: 300; color: #656565; } .box { width: 500px; max-width: 90%; margin: 5rem auto; padding: 3rem; display: block; border-radius: 1.5rem; background-color: rgb(255, 255, 255); box-shadow: 0px 0px 15.84px 0.16px rgba(35, 31, 32, 0.1); } .meter { width: 188px; margin: 30px auto 0; position: relative; } .meter-hand { position: absolute; left: 50%; bottom: 6px; margin-left: -44px; z-index: 1; transition: all 2s ease-in-out; transform-origin: 94% 48%; } .speed { font-size: 3.2rem; font-weight: 700; line-height: 1; } #speed { min-width: 100px; display: inline-block; } .unit { font-size: 2rem; font-weight: 500; color: #bbe697; } .meter .num { font-size: 1rem; font-weight: 600; position: absolute; } #num_1 { left: 25px; top: 80px; } #num_2 { left: 37px; top: 56px; } #num_3 { left: 55px; top: 35px; } #num_4 { left: 87px; top: 25px; } #num_5 { right: 55px; top: 35px; } #num_6 { right: 37px; top: 56px; } #num_7 { right: 25px; top: 80px; }

JQuery:
$(function() { var speed = $('#speed').text(); $('#hand').animate({ textIndent: 0 }, { step: function(now) { now = speed; $('.meter .num').each(function() { for (var i = 0; i <= 6; i++) { $('#num_' + (i + 1)).text(i * 30); } }) if ((now / 180) > 1) { var m = now / 180; $('.meter .num').each(function() { for (var i = 0; i <= 6; i++) { $('#num_' + (i + 1)).text(Math.round(i * 30 * m) * 2); } }) $(this).css('-webkit-transform', 'rotate(' + 90 + 'deg)'); } else { $(this).css('-webkit-transform', 'rotate(' + now + 'deg)'); } $('#speed').prop('Counter', 0).animate({ Counter: now }, { duration: 2000, easing: 'linear', step: function(now) { $('#speed').text(Math.round(now * 100) / 100); } }); }, duration: '1000' }, 'linear'); });


Live demo:
 https://jsfiddle.net/trickyui/jwj52wmh/

Bootstrap Carousel



Hello Friends, today you learn about Bootstrap Carousel Plugin. Basically Bootstrap Carousel is a slideshow component for cycling of elements like: images, videos, Content etc.
You can use this plugin individually (carousel.js) or with Bootstrap(bootstrap.js). You can't create nested carousel. Bootstrap carousel not working in IE8 & 9, because it's used CSS3 animations which is not supported in IE9 and lower versions. For run the carousel you have to add active class in one slide. Otherwise carousel will be hide.


<div id="imageslide" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#imageslide" data-slide-to="0" class="active"></li>
    <li data-target="#imageslide" data-slide-to="1"></li>
    <li data-target="#imageslide" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="image1.jpg" alt="">
    </div>
    <div class="item">
      <img src="image2.jpg" alt="">
    </div>
    <div class="item">
      <img src="image3.jpg" alt="">
    </div>
    <div class="item">
      <img src="image4.jpg" alt="">
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#imageslide" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#imageslide" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>


Bootstrap Carousel require an id on the outer container div to run Carousel functions properly. So when you add multiple Carousels in your page make sure to change the relevant controls.
Glyphicons is not mandatory to use. You can use your own image or fonts.


Javascript:
You can call the Carousel manually:
<script>
    $(document).ready(function(){
        $('.carousel').carousel()
    });
</script>

Options:
You can use Carousel options via data attributes or javascript.

Name default description
interval 5000 Number
The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.
pause "hover" String | Null
If set to "hover", pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If set to null, hovering over the carousel won't pause it.
wrap true Boolean
Whether the carousel should cycle continuously or have hard stops.
keyboard true Boolean
Whether the carousel should react to keyboard events.


For more detialed information please visit: http://getbootstrap.com/javascript/#carousel

How to use Bootstrap Glyph Icons.



Hi friends, today we learn how we can use glyphs font icons. Basically Glyphs are a font format from the Glyphicon Halflings set. Glyphicons Halflings are not free but in Bootstrap it's available free of cost. For using the Glyphicons we should include a link back to Glyphicons whenever possible.

All icons require a class and individual icon class. We can use Glyphicons in text, forms, toolbars, navigation, button etc.

To avoid confusion output in screen readers, we can hide them with the aria-hidden="true" attribute.





<span class="glyphicon glyphicon-search" aria-hidden="true"></span>





<span class="glyphicon glyphicon-star" aria-hidden="true"></span>


For more detailed information you can visit http://getbootstrap.com/components/#glyphicons-glyphs

Bootstrap Popovers


Hello Friends! In this blog you will learn, how to create a Popover. Before learn it, you have to know that what is Popover. Popover is similar to a Tool tip. Popover is a pop-box which is bigger in size and can contain much more content. You can be include Popover plugin individually in your project or use bootstrap.js.

• Use the data-content attribute to specify the text of Popover.
• Use title attribute for Popover header text.
• Use data-placement attribute to specify the location of Popover.

<a href="#" data-toggle="popover" data-placement="right" title="Header Text" data-content="Some content inside the popover">Toggle popover</a> 


You have to initialized Popover plugin. Simply call the Popover method. 

<script> 
$(document).ready(function(){
      $('[data-toggle="popover"]').popover(); 
}); 
</script> 

 For detialed information you can visit: http://getbootstrap.com/javascript/#popovers

Bootstrap Togglable tabs


Now you can create toggable tabs with bootstrap. It's very simple. Use bootstrap toggle functionality and enjoy it in your project with very simple method. Before use bootstrap tabs you have to enable tabbable tabs via javascript. After enable tabs now you can use it easily. It is fully customizable. You can create your own theme for tabs.

Java Script:

Enable tabs >

$('#myTabs a').click(function (e) {
      e.preventDefault()
      $(this).tab('show')
})

HTML:
 <div>
<ul class="nav nav-tabs" role="tablist">
      <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
      <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
      <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
      <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>


<div class="tab-content">
      <div role="tabpanel" class="tab-pane active" id="home">...</div>
      <div role="tabpanel" class="tab-pane" id="profile">...</div>
      <div role="tabpanel" class="tab-pane" id="messages">...</div>
      <div role="tabpanel" class="tab-pane" id="settings">...</div>
</div>
</div>