Search here for other jquery codes


October 13, 2013

jquery code to check if checkbox/radio button is checked or unchecked

I would let you know a simple jquery script to check if a checkbox or radio buttton is clicked or unclicked.

The code is pretty simple, So their is no explanation needed

Here is the checkbox


<input type="checkbox" id="singledate" name="singledate" value="Choose single day" />Single date


Here is the jquery code which will perform something after check and uncheck, you can add your custom function instead of alert.



<script type="text/javascript">

$("#singledate").click(function(){

  if($('input[name=singledate]').is(':checked') == true ){

            alert("checked");
     }
     else
    {
           alert("unchecked");
    }
});

</script>


Thats it, help this blog to grow, visit other cool code links! :)

how to create Google like vertical page scroll in jQuery

Hi,

Here is a simple dynamic function to create a smooth ,Google plus like animated vertical page scroll in jQuery.

Create a page with various divisions and give a unique "id" to it.

Also, create another div and name the ID as "div_name", we will access this to display the name of the scrolled division.

<div id="div_name</div>                                           

create links and onclick of each link call the JavaScript function "scroll_section(ide)" , will see it in detail next.

<a href="javascript: void(0);" onclick="scroll_section("div10")">Division10</a>

here, "div10" is the ID of the division you want the page to be scrolled.

Now for the function,

function scroll_section(ide)
{
     $('#div_name').html("Page"+ide).animate({top:"15px"},1000);
     $('html,body').animate({scrollTop: $("#"+ide).offset().top},1000);
}

The first code in the function, is used to display the name of the current division you have scrolled into, with the animation delay of 1000 ms and $('#div_name').html("Page"+ide) will output the name of that division, hence make sure you give genuine name to ID tag.

$('#div_name').html("Page"+ide).animate({top:"15px"},1000);

The second piece of code will actually find the div element you have called and it will scroll that particular division onto the window top with smooth scrolling, with a delay of 1000ms.

$('html,body').animate({scrollTop: $("#"+ide).offset().top},1000);

That is it guys!.

kindly help the blog to grow in anyway you can. ;)

Google beta like menu in jquery

I just love google's new look, especially the menus in Beta version. have you noticed the border that appears for each link which you have selected?. Well lets learn how to create one such fantastic menu button using jquery and css.

Include jquery library

create a HTML page and few link texts


<div id="menu">
<div class="normal"> Everything </div>
<div class="normal"> Images </div>
<div class="normal"> Maps </div>
</div>


Write a little css fo the same

.normal{
    width:100px; height:30px;
    margin:5px; padding:5px 5px 5px 15px;
    background: #FFFFF;
    text-align:left;
    border:#fff solid 5px;
    cursor:pointer;  
}

.clicked{

    width:100px; height:30px;
    margin:5px; padding:5px 5px 5px 15px;
    background: #FFFFF; color:#FF0000;
    text-align:left;
    border-left:#00cc00 solid 5px;
    cursor:pointer;
}

Now the Jquery to perform magic

$(document).ready(function () {
   
    $("#menu > div").each(function() {
       
        $("#menu > div").click(function() {
           
            $("#menu > div").removeClass("clicked");
            $(this).addClass("clicked").animate({ borderLeftWidth: "5px" }, 1500 );           
           
            });
       
        });
});

Thats it guys!!

Please subscribe if found useful  and click on other links to see more cool codes  :)

DEMO LOOK:

Google beta Menu

jquery image slider tutorial

Hi,

I would walk you through a tutorial on creating a simple , powerful jquery image slider with titles.

Features:
  1. Supports any number of images.
  2. shows animated caption or titles for each image.
  3. Thumbnail preview with scroll.
  4. Auto scroll back of thumbnails.
  5. works fine in many major browsers.
  6. Easy to code and maintain.

Ok, lets start...

After you include jQuery file do the following in your index file,create a division named "capsule" , it will hold our entire slider.Create another division named "image_viewer" to hold our image viewer and title. Last, create third division "galleryContainer" that holds our thumbnail images ,left and right navigation arrows.

NOTE: In order to show captions please write the respective image caption in the respective "title" tag for each image.

complete HTML here:

<div id="capsule">
   <div id="image_viewer">
     <!-- To append click images-->
       <img src="" />
     <!-- To append image titles-->
       <span id="img_title" class="img_title">&nbsp;</span>
   </div>
<div id="galleryContainer">
   <div id="arrow_left"><img src="images/arrow_left.gif"></div>
   <div id="arrow_right"><img src="images/arrow_right.gif"></div>
   <div id="innerscroll">

<!-- Thumbnails -->
<img src="images/Blue hills.jpg" title="picture1" class="image">
<img src="images/Sunset.jpg" title="picture2" class="image">
<img src="images/Water lilies.jpg" title="long text caption test with this one" class="image">
<img src="images/Winter.jpg" title="picture 3" class="image">
<img src="images/Blue hills.jpg" title="picture4" class="image">
<img src="images/Sunset.jpg" title="picture5" class="image">
<img src="images/Water lilies.jpg" title="long text caption test with this one" class="image">
<img src="images/Winter.jpg" title="picture 7" class="image">
<!-- Thumbnails end -->

   </div>
 </div>
</div>

Now for the important one, jQuery!

The comments are self explanatory, so am not talking more about it!.

$(document).ready(function() {

<!-- On page load calculate length of thumbnail images -->
var x = parseInt ($('#innerscroll img').length)- 2; // remove count for 2 images left and right arrow
var count=1; //set counter to calculate image rotation
<!-- end of variale declaration -->

<!-- On page load show default first image and title as viewer image -->
var path = $('#innerscroll>img:first').attr('src');
var caption = $('#innerscroll>img:first').attr('title');
$('#image_viewer>img').attr('src', path).animate({"easing": "linear",'opacity': "1.0"}, 500).show();
$('#image_viewer>span').html("").slideUp('fast');
$('#image_viewer>span').html(caption).slideDown('slow');
<!-- end of action -->

<!-- On click of left arrow move thumbnails and animate right arrow with bright image and dull the current arrow -->
    $('#arrow_left').click(function (event){
    $('#arrow_left img').attr('src','images/arrow_left.gif');
    $('#arrow_right img').attr('src','images/arrow_right_over.gif');
     if(count>3){ count=1; $('#innerscroll').animate({left: 0}, 500); $('#arrow_right  img').attr('src','images/arrow_right.gif');}
    else {
$('#innerscroll').animate({"left": "+=150px",'opacity': "0.5"}, 500).animate({"easing": "easeout",'opacity': "1.0"}, 500);
count++;
}
});
<!-- end of action -->

<!-- On click of right arrow move thumbnails and animate left arrow with bright image and dull the current arrow -->
$('#arrow_right').click(function (event){
$('#arrow_right img').attr('src','images/arrow_right.gif');
$('#arrow_left img').attr('src','images/arrow_left_over.gif');
if(x<count){count=1; $('#innerscroll').animate({left: 0}, 500); $('#arrow_left img').attr('src','images/arrow_left.gif'); }
else {
$('#innerscroll').animate({"left": "-=150px",'opacity': "0.5"}, 500).animate({"easing": "easeout",'opacity': "1.0"}, 500);
count++;
}
});
<!-- end of action -->

<!-- On click of thumbnail load or append the current image and title in the image_viewer division -->
$("#innerscroll img").click(function(){
var path = $(this).attr('src');
var caption = $(this).attr('title');
$('#image_viewer>img').attr('src', path).animate({"easing": "linear",'opacity': "0.5"}, 500).animate({"easing": "linear",'opacity': "1.0"}, 500).show();
$('#image_viewer>span').html("").slideUp('fast');
$('#image_viewer>span').html(caption).slideDown('slow');
});
<!-- end of action -->

});

Finally css :

TIP: Make sure your "#image_viewer" and "#image_viewer img" width are same , to get full image view.

<style type="text/css">

.scrollable{
position:relative;width:610px; height:150px; overflow:hidden; margin:5px;
}

.image{width:150px; height:100px; float:left; display:block; cursor:pointer; margin:2px;
}

.container{ margin:5px; padding:5px; width:690px; background:#fff;
}

.container_theater{ margin:5px; padding:5px; width:690px; background:#000000;
}

#image_viewer{
border:#000000 solid 5px; width:685px; height:300px;
}

#image_viewer img{
width:685px; height:300px;
}

.img_title{
border:#999999 solid 1px; width:100%; height:25px; text-align:center; margin-top:-25px; float:right; opacity: .8; z-index:15; background:#CCCCCC;font-family:Verdana; font-style:oblique; font-weight:800; display:none;
}

#arrow_left{position:absolute;float:left;z-index:10;background-color: #FFF;padding:0px;margin-top:2px;cursor:pointer;
}

#arrow_right{
position:absolute;float:left;right:0px;z-index:10;background-color: #FFF;padding:0px;margin-top:2px;cursor:pointer;
}
#innerscroll{position:absolute;height:100px;left:40px;width:10000px;
}

#galleryContainer{height:102px; /* Height of the images + 2 */
border:1px solid #CCCCCC;
position:relative;overflow:hidden;padding:0px;width:690px;height: 104px;/* IE 5.x - Added 2 pixels for border left and right */
height/* */:/**/102px; /* Other browsers */
height: /**/102px;
}

</style>

Here is how it looks:


jQuery slider by sree
Thats all guys, feedbacks are welcome!

help this blog to grow in anyway you can! :)

October 12, 2013

Best opensource free javascript graph api-plugin

For quiet a few days now i had been searching for various online sources to get opensource jquery based graphs/charts, ofcource, as a freelancer i needed free graphs.
So, after some research i have come down to top two best opensource jquery based graphs based on their interactivity, documentation,UI and ease of use. I have also taken into consideration about various types that these api's support, like bar graph,pie chart, area chart etc...
Ok ready? here you go...

Google Chart Tools

Oh yeah! anything on the web apps, Google has to be their,  right at the top.

Now, the reason , is simple, it provides various types of graphs that are interactive , easy to implement and works across all the browsers !. The more coolest thing is the clear picture with its awesome documentation. The X-factor being the geocharts and all for free!

Google -  geo chart example

One point to be taken care is that , for a commercial purpose the geo chart MAY BE limited. i will post more on that or perhaps  you can comment and let me know.


Highcharts

Amazing UI chart, with interactive- animation using javascript and free for non commercial use.
This javascript graph library tops in many aspects!. It has a relatively good documenation. It has got themes, which is pretty impressive. My personal opinion is that highchart has more inter activeness than Google chart.

Highchart - javascript graph
Look at the highchart demo for more instruction.

Please note that you have to pay in order to use it for commercial purpose!

jplot

jplot is another very good jquery based opensource chart library that can be used to deploy graphs. The advantage of jplot is that it has lot of options to play around , ability to easily plug with the data and ofcourse it is an open source.

jplot- jquery based graph library
you can see the jplot working demo here.

The disadvantage is that , it lacks interactivity unless like that of G graphs or highcharts.

So fa,r i found these top 3 usable graphs. Perhaps you can share more in the comments and help others!

subscribe and visit more cool codes below!