Tag Archives: learn jquery online

jQuery Events


jQuery Events represents the happenings in the page.


jQuery Event Types with Example

  • Button click
  • Mouseover
  • Scrolling page
  • Selecting check box
  • Double click
  • Keypress

jQuery Events with click example


jQuery Events – click() example


    

Try it »

jQuery Event with double click example

jQuery Events – dblclick() example


    

Try it »


jQuery Event with mouseover() example


jQuery Events – Mouseover example


    

Try it »


jQuery Event with blur() example


jQuery Events – blur example


    

Try it »

tr odd Selects all odd rows of table – jQuery


$( “tr:odd” ) – selector is used to select the odd rows of the table.


tr odd Selects all odd rows of table with jQuery syntax

tr odd Selects all odd rows of table – jQuery Example


 
 
  
	

 
Click Me To Select Odd Rows


Jhohnjhone@gmail.comUSA
Kellykelly@gmail.comUSA
Kamanakamna@gmail.comIndia
Anayanay@gmail.comCanada
AnaMyamy@gmail.comCanada
Rummyasd@gmail.comCanada
Jellyy@gmail.comCanada

Try it »

Note : Row Index starts from 0,1,2….

first-child Selector- jQuery


$( “:first-child” ) – selector is used to select the first child of its parent.


Syntax : first-child Selector using jQuery

first-child Selector- jQuery Example


 
 
  
	

 
Click Me

  1. First Item
  2. Second Item
  3. Third Item

Try it »

Class Selector jQuery Example


$(“.class”) – selector is used to select the elements in the page which have class “.class”.


Class Selector jQuery Example – $(“.class”)

Class Selector jQuery Example with syntax


 
 
  
	

   
Div One..

Div Two..

Paragraph..

Span...

Try it »

All Selector – select all elements in a page- jQuery


All Selector (*) selects all the elements of the page.


All Selector – select all elements in a page with jQuery(*) Syntax

All Selector – select all elements in a page- jQuery Example


 
 
  
	

Div One..

Div Two..

Paragraph..

Span...

Try it »

Facebook style cover image reposition in php jquery

Facebook style cover image reposition in php jquery : In this post we are going to explain the functionality implemented just like facbook style cover image repostion in php and jquery.

Jquery Ui : Jquery ui is used to enable the draggable functionality for the selected image.

Php : We are using php on sever side to resize and crop the image on co-ordinates provided. Co-ordinates are passed to the server selected by the user.

Jquery Ui Draggable : Provides the draggable functionality on element. Event is triggered when we move mouse on the
element ie image in this case.
Jquery Function used for draggable functionality.

Facebook style cover image in PHP with Syntax

Jquery Ui : Draggable

function initUi(){
     
     
    $(function(){
    $(".coverimage").css('cursor','s-resize');
    var y1 = $('.imagecontainer').height();
    var y2 = $('.coverimage').height();
    $(".coverimage").draggable({
       scroll: false,
       axis: "y",
       drag: function(event, ui) {
             if(ui.position.top >= 0)
             {   
                                         
               ui.position.top = 0;
                                          
              }
              else if(ui.position.top <= y1 - y2)
              {
               ui.position.top = y1 - y2;
                                          
               }
    
            },
            stop: function(event, ui) {
            //####          
            $("#top").val(ui.position.top);
           
        }
        });                    
});
 }

Main page with above code and main layout : index.php

Javascript Code to handle the drag and save event.





  
  
  
  
  
  
  
  


    
  

PHP Code On Server Side : functions.php

Php code to Resize And Crop the image to Fit on container

 $h) {
      $imageHeight = floor(($h/$w)*$width);
      $imageWidth  = $width;
    } else {
      $imageWidth  = floor(($w/$h)*$height);
      $imageHeight = $height;
    }
    $x = 0;
  
  $new = imagecreatetruecolor($imageWidth, $imageHeight);
  // preserve transparency
  if($type == "gif" or $type == "png"){
    imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
    imagealphablending($new, false);
    imagesavealpha($new, true);
  }
  imagecopyresampled($new, $img, 0, 0, $x, 0, $imageWidth, $imageHeight, $w, $h);
  switch($type){
    case 'bmp': imagewbmp($new, $dst); break;
    case 'gif': imagegif($new, $dst); break;
    case 'jpg': imagejpeg($new, $dst); break;
    case 'png': imagepng($new, $dst); break;
  }
  return true;
}
function crop($source,$destination,$destinationWidth,$destinationHeight,$x1,$y1){
     if(!list($w, $h) = getimagesize($source)) return "Unsupported picture type!";
     $type = strtolower(substr(strrchr($source,"."),1));
      if($type == 'jpeg') $type = 'jpg';
      switch($type){
        case 'bmp': $copy = imagecreatefromwbmp($source); break;
        case 'gif': $copy = imagecreatefromgif($source); break;
        case 'jpg': $copy = imagecreatefromjpeg($source); break;
        case 'png': $copy = imagecreatefrompng($source); break;
        default : return "Unsupported picture type!";
      }
      // this is taken because of maintaining the aspect ratio for the croping to the exact height and width.
      $w = $destinationWidth;
      $h = $destinationHeight; 
      $new = imagecreatetruecolor($destinationWidth, $destinationHeight);
      imagecopyresampled($new, $copy, 0, 0, $x1, $y1, $destinationWidth, $destinationHeight, $w, $h);
       switch($type){
        case 'bmp': imagewbmp($new, $destination); break;
        case 'gif': imagegif($new, $destination); break;
        case 'jpg': imagejpeg($new, $destination); break;
        case 'png': imagepng($new, $destination); break;
      }
    return true;
}
?>

Main crop.php handling the complete server process :

Javascript Code to handle the drag and save event.

';

?>

Demo »

DemoDownload

Facebook style select box

Facebook style select box

Facebook Style Select box using Jquery ui.

It provides stylish select dropdown menu. It provides the functionality of the select drop down like facebook select
box.
Preview :

Facebook Style Select box dropdown menu

Facebook Style Select dropdown menu

Following Jquery and Css are Required for the functionality.
Add the following Jquery and css in the header of the page.

Demo syntax for Facebook style select box

Example

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Facebook Style Jquery Select Dropdown Demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#status" ).selectmenu();
});
</script>
<style>
fieldset {
border: 0;
}
label {
display: block;
margin: 35px 0 0 0;
}
select {
width: 290px;
}
.overflow {
height: 290px;
}
</style>
</head>
<body><div class="main-demo">

<form action="#">

<fieldset>
<label for="speed">Select a Status</label>
<select name="status" id="status">
<option selected="selected">Public</option>
<option>Friends</option>
<option>Only Me</option>
</select>
</form>

</div>

</body>
</html>

Demo »