Sunday, December 14, 2014

Get input file image in base64 encoded using jQuery.

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.1.min.js"></script>

<style type="text/css">

#base{
  padding:10px;
  background:#eee;
}

</style>

</head>
<body>


<input type='file' id="asd" />
<img id="img" src="" />
<div id="base"></div>

<script type="text/javascript">

function readImage(input) {
    if ( input.files && input.files[0] ) {
        var FR= new FileReader();
        FR.onload = function(e) {
             $('#img').attr( "src", e.target.result );
             $('#base').text( e.target.result );
        };    
        FR.readAsDataURL( input.files[0] );
    }
}

$("#asd").change(function(){
    readImage( this );
});

</script>

</body>
</html>


Output :)

1)

2)

Saturday, December 13, 2014

Use Thumbnail Image instead of radio button with CSS3.

<style type="text/css">

.cc-selector input{
    margin:0;padding:0;
    -webkit-appearance:none;
       -moz-appearance:none;
            appearance:none;
}

.visa{ background-image:url(http://i.imgur.com/lXzJ1eB.png); }

.mastercard{ background-image:url(http://i.imgur.com/SJbRQF7.png); }

.cc-selector input:active +.drinkcard-cc{ opacity: .9; }

.cc-selector input:checked +.drinkcard-cc{
    -webkit-filter: none;
       -moz-filter: none;
            filter: none;
}

.drinkcard-cc{
    cursor:pointer;
    background-size:contain;
    background-repeat:no-repeat;
    display:inline-block;
    width:100px;height:70px;
    -webkit-transition: all 100ms ease-in;
       -moz-transition: all 100ms ease-in;
            transition: all 100ms ease-in;
    -webkit-filter: brightness(1.8) grayscale(1) opacity(.7);
       -moz-filter: brightness(1.8) grayscale(1) opacity(.7);
            filter: brightness(1.8) grayscale(1) opacity(.7);
}

.drinkcard-cc:hover{
    -webkit-filter: brightness(1.2) grayscale(.5) opacity(.9);
       -moz-filter: brightness(1.2) grayscale(.5) opacity(.9);
            filter: brightness(1.2) grayscale(.5) opacity(.9);
}

/* Extras */
a:visited{ color:#888; }
a{ color:#444; text-decoration:none; }
p{ margin-bottom:.3em; }

</style>

<form>
    <p>Previously:</p>

    <div>
        <input id="a1" type="radio" name="a" value="visa" />
        <label for="a1">Visa</label><br/>
        <input id="a2" type="radio" name="a" value="mastercard" />
        <label for="a2">Mastercard</label>
    </div>

    <p>Now, with CSS3: </p>

    <div class="cc-selector">
        <input id="visa" type="radio" name="credit-card" value="visa" />
        <label class="drinkcard-cc visa" for="visa"></label>
        <input id="mastercard" type="radio" name="credit-card" value="mastercard" />
        <label class="drinkcard-cc mastercard"for="mastercard"></label>
    </div>
</form>


Output :)

1)

2)

3)

Friday, December 12, 2014

How to Preview Image, get file size, image height and width before upload Using JQuery?

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.1.min.js"></script>

<style type="text/css">

*{ font-family: verdana; }
#uploadPreview img{ height:200px; width:200px; }

</style>
</head>

<body>
<input type="file" id="choose" multiple="multiple" /> <br/>
<div id="uploadPreview"></div>
</body>

<script type="text/javascript">

$(function(){
function readImage(file) {
var reader = new FileReader();
var image  = new Image();

reader.readAsDataURL(file);
reader.onload = function(_file) {
image.src    = _file.target.result;
image.onload = function() {
var w = this.width,
h = this.height,
t = file.type,
n = file.name,
s = ~~(file.size/1024) +'KB';
$('#uploadPreview').append('<img src="'+ this.src +'"> '+w+'x'+h+' '+s+' '+t+' '+n+'<br>');
};
image.onerror= function() {
alert('Invalid file type: '+ file.type);
};
};
}

$("#choose").change(function (e) {
if(this.disabled) return alert('File upload not supported!');
var F = this.files;
if(F && F[0]) for(var i=0; i<F.length; i++) readImage( F[i] );
});
});

</script>
</html>

Output :)

1)

2)

Thursday, December 11, 2014

Using a background image for clear text.

<form action="" method="get">
   <input type="text" name="search" required="required" placeholder="type here"/>
   <input type="reset" value="" alt="clear" />
</form>

<style>

   input[type="text"]
   {
      height: 38px;
      font-size: 15pt;
   }

   input[type="text"]:invalid + input[type="reset"]{
     display: none;
   }

   input[type="reset"]
   {
      background-image: url( http://png-5.findicons.com/files/icons/1150/tango/32/edit_clear.png );
      background-position: center center;
      background-repeat: no-repeat;
      height: 38px;
      width: 38px;
      border: none;
      background-color: transparent;
      cursor: pointer;
      position: relative;
      top: -9px;
      left: -44px;
   }

</style>


Output :)

1)

2)

Wednesday, December 10, 2014

How to change the class of several tds of table when hovering over one of them using JQuery?

<style type="text/css">

.blocked {
   color: white;
   background-color: red;
}

.start {
   border-left: 5px solid black;
}

.end {
   border-right: 5px solid black;
}

.blocked-highlight {
   background-color: blue;
}

</style>

<script type="text/javascript" src="jquery-1.11.1.min.js"></script>

<table>
    <thead><tr>
            <th>Monday</th>
            <th>Tuesday</th>
            <th>Wednesday</th>
            <th>Thursday</th>
            <th>Friday</th>
            <th>Saturday</th>
            <th>Sunday</th>
    </tr></thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
            <td>5</td>
            <td>6</td>
            <td>7</td>
        </tr>
        <tr>
            <td>8</td>
            <td>9</td>
            <td>10</td>
            <td>11</td>
            <td>12</td>
            <td>13</td>
            <td>14</td>
        </tr>
        <tr>
            <td>15</td>
            <td>16</td>
            <td class="blocked start">17</td>
            <td class="blocked">18</td>
            <td class="blocked">19</td>
            <td class="blocked">20</td>
            <td class="blocked">21</td>
        </tr>
        <tr>
            <td class="blocked">22</td>
            <td class="blocked">23</td>
            <td class="blocked end">24</td>
            <td>25</td>
            <td>26</td>
            <td>27</td>
            <td>28</td>
        </tr>
        <tr>
            <td>29</td>
            <td>30</td>
            <td>31</td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </tbody>
 </table>

 <script type="text/javascript">

$( document ).ready(function() {
   $("td.blocked").hover(
       function() {
           $( this ).siblings('.blocked').addBack(".blocked").addClass('blocked-highlight')
       }, function() {
           $( this ).siblings('.blocked').addBack(".blocked").removeClass('blocked-highlight')
       }
   );
});

 </script>


Output :)

1)

2)

3)


Tuesday, December 9, 2014

Vertical Nav Menu That Scrolls Then Also Has A Fly Out.

<style type="text/css">

  * {
    margin: 0px;
    padding: 0px;
  }
  a {
    color:inherit;
    text-decoration: none;
  }
  #container {
    height: 190px;
    overflow-y: auto;
  }
  ul#navmenu a:hover {
    color: #FFF;
  }
  body {
    font-size: 15px;
    font-family:Verdana;
    padding: 50px;
    color: #555555;
  }
  ul#navmenu, ul.sub1, ul.sub2 {
    list-style-type: none;
  }
  ul#navmenu li {
    width: 310px;
    text-align: center;
    position: relative;
    border-bottom: 0.12em dotted #ABB0B0;
    text-align: left;
  }
  ul#navmenu a {
    text-decoration: none;
    display: block;
    width: 300px;
    height: 45px;
    line-height: 45px;
    background-color: #E5E8E9;
    padding-left: 10px;
  }
  ul#navmenu .sub1 li {
  }
  ul#navmenu .su1 a {
    margin-top: 5px;
  }
  ul#navmenu .sub2 a {
    margin-left: 10px;
    width: 300px;
  }
  ul#navmenu li:hover > a {
    background-color: #0098ba;
  }
  ul#navmenu li:hover a:hover {
    background-color: #0098ba;
  }
  ul#navmenu ul.sub1 {
    display: none;
    position: absolute;
    top: 45px;
    left: 0px;
  }
  ul#navmenu ul.sub2 {
    display: none;
    position: absolute;
    top: -92px;
    left: 300px;
    width: 400px;
  }
  ul#navmenu li:hover .sub1 {
    display: block;
  }
  ul#navmenu .sub1 li:hover .sub2 {
    display: block;
  }
  .sub2 {
    text-transform: capitalize;
    font-size: 14px;
  }
  .button {
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    border: solid 1px #c7c7c7;
    color: #006792;
    cursor: pointer;
    -webkit-appearance: button;
    box-shadow: inset 0 -1px #c7c7c7;
  }
  .triangleTop {
    position:relative;
    left: 270px;
    top: 30px;
    width: 0;
    height: 0;
    border-right: 10px solid transparent;
    border-bottom: 10px solid #0098ba;
    border-left: 10px solid transparent;
    z-index: 2;
  }

</style>

<body>
  <div id="container">
    <div class="triangleTop"></div>
    <ul id="navmenu">
      <li><a>Hover on me</a>

        <ul class="sub1">
          <li><a href="#">MaHi</a></li>
          <li><a href="#">Sonal</a></li>
          <li><a href="#">Cities</a>
            <ul class="sub2">
              <li><a href="#">Surat</a></li>
              <li><a href="#">Bhavnagar</a></li>
              <li><a href="#">Ahmedabad</a></li>
              <li><a href="#">Rajkot</a></li>
              <li><a href="#">Baroda</a></li>
              <li><a href="#">Navsari</a></li>
              <li><a href="#">Valsad</a></li>
              <li><a href="#">Baruch</a></li>
              <li><a href="#">Mumbai</a></li>
              <li><a href="#">Panchgini</a></li>
              <li><a href="#">Pune</a></li>
              <li><a href="#">Nagpur</a></li>
            </ul>
          </li>
          <li><a href="#">Country</a></li>
          <li><a href="#">Sport</a></li>
          <li><a href="#">Hobby</a></li>
          <li><a href="#">Love</a></li>
          <li><a href="#">Man City FC</a></li>
          <li><a href="#">Bike</a></li>
          <li><a class="button">Manage content collections</a></li>
        </ul>
      </li>
    </ul>
  </div>
</body>


Output :)

1)

2)

3)

Monday, December 8, 2014

Continuous scroll on hover [performance] using JQuery.

<style type="text/css">

.scroll{
   margin-top:20px;
   background:#444;
   height:20px;
}

#content{
   width:0px;
   padding:10px;
   margin-left:0px;
   background:red;
   border-radius:100px;
}
.scroll:hover #content{
   background:lightgreen;
}

</style>

<script type="text/javascript" src="jquery-1.11.1.min.js"></script>

<div class="scroll">
    <div id="content"></div>
</div>

<script type="text/javascript">

$(function(){
function loop(){
    $('#content').stop().animate({marginLeft:'+=20'}, 1000, 'linear', loop);
}

function stop(){
   $('#content').stop();
}

$(".scroll").hover(function () {
  loop();
},function () {
  stop();
});
});

</script>

Output :)

1)

2)

3)