Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Monday, November 12, 2012

Christmas effects on HTML page

On this page you can find links to christmas javascript effects which can be applied on your web page.

We will start with two snow effect, then continue with moving santa.

Look below for links to christmas effect tutorials!








Christmas snowing javascript effect - find how to add snowing effect on your web page. Following this link more advanced users can also find how to make snow fall with a custom snow flakes.

Snow fall effect sample from my blog











Moving santa on your HTML page - how to get moving christmas Stana Claus on your HTML page with a help of javascript.

Animate - Moving image effect on web page










3D snow effect in HTML5 - want a window looking on 3D falling snow on your HTML page? This impressive 3D effect you can find by following the link.

3D snow effect with HTML5 and javascript












jQuery snow falling effect - if you like jQuery, linked article could teach you how to add snowing effect on you web site using jQuery.

jQuery snowing effect animation sample

Thursday, November 8, 2012

jQuery snow falling effect on your blog

How to get jQuery snowing effect animation on your blog or web site?

Very easy, you just need to copy a few lines of HTML code plus a few lines of jQuery code and your web page will snowing, many snowflakes will fall.

jQuery snow falling effect is visible on this page. If you look at page you will see falling snowflakes.


To get same (jQuery) snow effect you need to include this code on your page:

<script src="http://code.jquery.com/jquery-1.8.2.min.js" 
type="text/javascript"></script>
<script src="http://cloud.github.com/downloads/kopipejst/jqSnow/jquery.snow.js" 
type="text/javascript"></script>

<script>
 $(document).ready( function(){
         $.fn.snow();
 });
 </script>

So, to get jQuery snowing effect you just need to copy code above and paste it on your HTML page.

First four lines of HTML code are links to jquery-1.8.2.min.js and to jquery.snow.js files. Lines 6 to 10 is jquery code which call snow method from jquery.snow.js file.

jQuery snowing effect animation sample

You can download jquery.snow.js file from WORKSHOP owned by Ivan Lazarevic (the author of snowing script code), then upload this file somewhere on internet and use it for your blog or web site.

There is another snowing effect on my blog written in ordinary javascript.


Wednesday, September 19, 2012

Change image onclick with jQuery

Learn how to change image when onclick event occurs (with help of jQuery). My previous article was about how to change image with onclick event with common javascript. This article is focused on doing the same thing but with jQuery.

First there will be one simple demonstration of changing image with onclick event with two buttons. Each button change image when clicked.

Second demonstration is how to change image when onclick event is happened on that image. So, image is changed every time user click on it.

Changing image after onclick event on button with jQuery

changing image when onclick event occurs

  

When "Show Undo" button is clicked arrow is pointed to left, when "Show Redo" is clicked image is changed to arrow pointed to left.

Let's take a look at code:


<p><img alt="" src="http://www.userinterfaceicons.com/80x80/redo.png" style="height: 85px; width: 198px" id="ChangeImage" />
</p>
     
<p><input id="Undo" type="button" value="Show undo" />&nbsp;&nbsp; <input id="Redo" type="button" value="Show Redo"  />
</p>


    <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#Undo").click(function () {
                $('#ChangeImage').attr('src', 'http://www.userinterfaceicons.com/80x80/undo.png');
            });
            $("#Redo").click(function () {
                $('#ChangeImage').attr('src', 'http://www.userinterfaceicons.com/80x80/redo.png');
            });
        });
    </script>

Explanation of code for alternating image:

  • on the top there are HTML code for image and two buttons
    
    <p><img alt="" src="http://www.userinterfaceicons.com/80x80/redo.png" style="height: 85px; width: 198px" id="ChangeImage" />
    </p>
         
    <p><input id="Undo" type="button" value="Show undo" />&nbsp;&nbsp; <input id="Redo" type="button" value="Show Redo"  />
    </p>

  • to use jQuery we need to have a call to jQuery library
    
       <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

  • the main part of jQuery code, two onclick events, when input Undo is clicked image with id "ChangeImage" is changed to Undo image.

  • when input Redo is clicked image with id "ChangeImage" is changed to Redo image
    
     <script type="text/javascript">
            $(document).ready(function () {
                $("#Undo").click(function () {
                    $('#ChangeImage').attr('src', 'http://www.userinterfaceicons.com/80x80/undo.png');
                });
                $("#Redo").click(function () {
                    $('#ChangeImage').attr('src', 'http://www.userinterfaceicons.com/80x80/redo.png');
                });
            });
        </script>
    

Alternate image when image is clicked with jQuery

When image below is clicked, image is changed.

Check code how to accomplish change image when onclick event is raised:


  <img src="http://www.userinterfaceicons.com/80x80/undo.png" class="img-swap" />

 <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script>
        $(function () {
            $(".img-swap").live("click", function () {
                if ($(this).attr("class") == "img-swap") {
                    this.src = this.src.replace("undo", "redo");
                } else {
                    this.src = this.src.replace("redo", "undo");
                }
                $(this).toggleClass("on");
            });
        });
     </script>

How this code is working?

  • first line is image with class "img-swap"

  • then there is a function which occurs when object with class "img-swap" is clicked

  • if clicked class is "img-swap" then "undo" is replaced with "redo" for src attribute, so the other image is showed

  • if clicked class is not "img-swap" then "redo" is replaced with "undo" for src attribute, so the other image is showed

  • at the end we have - $(this).toggleClass("on") - this code add "on" to class "img-swap" so we get class "img-swap on", on the second click with - $(this).toggleClass("on") - we get only "img-swap"

Wednesday, December 21, 2011

Javascript effects tutorial

Few Javascript effects tutorial links can be found on this page. Learn how to hide HTML element on mouseover with javascript, various javascript image effects or how to change text with javascript on some event (like mouse click or mouse over).

    So, here we have:

  • javascript visual effects

  • javascript image effects

  • Other javascript effects

Find links to javascript effect code tips below!


Javascript visual effects


How to add a falling snow effect - learn how to add nice snowing effect on your web page or blog in few simple steps. Following this link more advanced users can also find how to make snow fall with a custom snow flakes.

Snow fall effect sample from my blog












How to show and hide HTML elements using Javascript - learn how to hide some HTML element (like textbox, div, table, table row) on click or mouse hover with javascript. There are over six samples to better explain how to do it.

Sample of hiding HTML div element











Javascript image effects


Dynamically change image with javascript effect - tutorial how to dynamically change image when a mouse pointer is over image (onmouseover and onmouseout).

Or find out how to alternate image onclick with javascript.

Dynamically change image with javascript effect











Jquery image preview effect - learn how to show image preview when user hover mouse pointer over link.

Image preview effect with jQuery











Moving image on my web site effect - tree samples and guide which describe how to make animate effect to move image through web page.

Animate - Moving image effect on web page











jQuery image zoom effect - sample and step by step guide how to make zoom effect on your web page, so zoomed portion of image is showed when user put mouse over normal size image.














Other javascript effects


Changing text with javascript - change text with javacript on some event like click the link.


HTML5 scrolling text effect with javascript - how to make animated scrolling text within HTML5 like Marquee with jQuery. In HTML5 Marquee is obsolete.


Basic web effect with jQuery - in this article you can find demos and sample code for basic effect functions in jQuery. There are: hide and show effect, fadeIn and fadeOut (disappearing) effect, slide down and slide up effect and animate effect.


Tuesday, October 25, 2011

HTML5 scrolling text

HTML5 will not support scrolling text (marquee), marquee is obsolete. There is no marquee element defined since HTML 4.01 specification.

This article will answer how to make animated scrolling text within HTML5.

One way is to use jQuery marquee plugin. In next section you will find simple guide how to make animated scrolling text effect like marquee with jQuery.

Animated scrolling text with jQuery Demo:

Demo for marquee scrolling right

Animated scrolling text with jQuery code:


 <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
  <script src="http://remysharp.com/downloads/jquery.marquee.js" type="text/javascript"></script>

<marquee behavior="scroll" direction="right" scrollamount="2" width="350"><p>Demo for marquee scrolling right</p></marquee>


So to have scrolling text effect in HTML5 you need to:

  • reference on jquery-1.3.2.min.js and jquery.marquee.js files

  • add a marquee HTML element


In Marquee HTML element you can adjust attributes such as:

  • direction - left, right, up and down

  • scrollamount - speed of scrolling

  • behaviour - such as slide, scroll and alternate

  • width

You can find jquery.marquee.js file.

In the end you have marquee like animated scrolling effect which you can use in HTML5.

Here you can find more cool javascript effects tutorials.


Wednesday, September 7, 2011

Change text to UPPERCASE with jQuery

How to convert text to uppercase with jQuery? It is very easy, just follow steps in this brief tutorial. To make things easy this article will provide two demo examples with jQuery code.

jQuery uppercase - change text to uppercase in messagebox

Demo:

Click here to uppercase

In this demo text "To uppercase with jquery!" is changed to uppercase "TO UPPERCASE WITH JQUERY!". When link "Click here to uppercase" is clicked changed text is showed in messagebox.

Explanation for uppercase:

jQuery have toUpperCase method which convert text to UpperCase. Here is a sample code:


<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

<div id="target">
  Click here for uppercase
</div>

<script>
    $('#target').click(function () {
        var strVal = 'To uppercase with jquery!'
        alert(strVal.toUpperCase());
    });
</script>

First line is reference on jQuery library which every page using jQuery must have.

Then we have "Click here for uppercase" link with id target.

Inside script tag we have function which is fired when item with id "target" is clicked. Variable strVal is changed to uppercase with method toUpperCase() and showed in messagebox.

Change text in input textbox to uppercase jQuery

Change to uppercase
 

Above is a link "Change to uppercase" which change text in input text box to uppercase.

Code:

 <div id="Change">
  Change to uppercase
 </div>
<input value="to uppercase" type="text" id="inpChng" />

<script>
    $('#Change').click(function () {
        var strVal = $("#inpChng").val();
        $("#inpChng").val(strVal.toUpperCase());
    });
</script>

In the code above when link in div with id "Change is clicked" value from input text control is taken and changed to uppercase.


Monday, July 25, 2011

jQuery picture zoom

How to make jQuery picture zoom effect in a simple way. This jQuery image zoom effect you can easy add to your web or maybe to blogger's post. On this blog you can find more useful jscript effect tutorials.

Let's first take a look how jQuery picture zoom look like:




So when visitor hover a mouse over small picture zoom portion of that image appeared on right side with help of jQuery. On mouseover, image is zoomed! I believe that this is one of the simplest implementation of picture zoom effect you can find on Internet.

To accomplish picture zoom with jQuery like in demo you need to add this code on your web page:


<script src="[PathToJqueryFile]" type="text/javascript"></script>

<script src="[PathTojqzoomFile]" type='text/javascript'></script>

<script type="text/javascript">

    $(function () {
        var options =
{
    zoomWidth: 275,
    zoomHeight: 275
}
        $(".jqzoom").jqzoom(options);

        var options2 =
{
    zoomWidth: 275,
    zoomHeight: 275,
    zoomType: 'reverse'
}

        $(".jqzoom2").jqzoom(options2);

    });
</script>
<!--JQZOOM-STOPS-HELP@-http://bloggerstop.net-->

<a href="[PathToBiggerImage]" class="jqzoom" style="" title="Paris">

  <img src="[PathToSmallerImage]"  title="kawasakigreen" style="border: 1px solid #666;"><br />
</a>


You can copy code above and replace green words with real values:

  • [PathToJqueryFile] - path to jquery-1.3.2.min.js file. You must have this file to implement any jQuery functionality on your web site. You can download this file here.

  • [PathTojqzoomFile] - path to jquery.jqzoom1.0.1.js file. This file is needed for zoom functionality. You can download this file here.

  • [PathToBiggerImage] - path to image that will be displayed as a zoomed part of picture (in example it is zoomed portion of image which appear on the right side of the screen)

  • [PathToSmallerImage] - path to image that will be displayed as a image that you can move cursor over it (in example this is left picture)



In the end, here is some real code that works but please use it just for testing purpose. If you want to implement jquery picture zoom fuctionallity on you page, please, do not use paths you find on demo code below but download jqury files and upload them somewhere.


<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="http://nikofer.opendrive.com/files/54142960_wVVW5/jquery.jqzoom1.0.1.js" type='text/javascript'></script>

<script type="text/javascript">

    $(function () {
        var options =
{
    zoomWidth: 275,
    zoomHeight: 275
}
        $(".jqzoom").jqzoom(options);

        var options2 =
{
    zoomWidth: 275,
    zoomHeight: 275,
    zoomType: 'reverse'
}

        $(".jqzoom2").jqzoom(options2);

    });
</script>
<!--JQZOOM-STOPS-HELP@-http://bloggerstop.net-->

<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS8KHDSFc9LUf7Z8GIo920lA6j_EjMvQOCvQcT5puVzZoH3-i_MYjha2w4Siej9wd2utJSwagutC5UHGDvYZcV2dgGq0kI8dn5GsF1PPpYakYosgenP59zW69JohD-Ai3e-Zws-w46YYE/s800/SealSmall.jpg" class="jqzoom" style="" title="Paris">

  <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2KDEWmLwz2Mx5wo-3cBnjNn-4e_HPYx6xzeMAikXolzag2JN7SJcO21oMpe-R_k9pW_wIusC1YjgnrLHPn74FHrspa1DpeSs-QKgF4nKkRli8dMH7V-mxipLbY95SMVgcIeXqJng0Tnk/s144/SealBig2.JPG"  title="kawasakigreen" style="border: 1px solid #666;"><br />
</a>

Sunday, August 2, 2009

jQuery image preview

Here you will learn how to dynamically preview image on your web page with help of jQuery. The image preview shows up when user put mouse pointer over the link. After mouse pointer lost focus on link, image preview disappear. Take a look at image preview demo to better understand what we call web image preview.



Demo of jQuery image preview



When visitors cursor hovering over "The sunset" link, an image preview shows up. After mouse pointer is moved off, image preview disappear. Now we will discuss how to install preview image on your page or blog (there are more javascript effect tutorials on my blog).


On this blog you can find how to alternate image after onclik event.


For those interested in changing image when onclick event occurs with jQuery I leave the link.

Guide to implement jQuery image preview on your page


  • Your page should point to external jquery library and to imgpreview plugin
    <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
    
    <script src="http://plugins.jquery.com/files/imgpreview.min.0.22.jquery.js.txt" type="text/javascript"></script>
  • We need some HTML code, one unordered list with one list item. This list item must have link to image
    <ul id="first">
    <li><a href='http://www.freefoto.com/images/15/10/15_10_70_thumb.jpg' rel="nofollow">The Sunset</a>
    </li>
    </ul>
  • Add jQuery code which instruct that when mouse pointer is over unordered list (ul) with id "first", method imgPreview is called. This method shows the image.
    <script type="text/javascript">
    $(document).ready(function(){
    $('ul#first a').imgPreview({
    imgCSS: { width: 100 }
    });
    });
    </script>


    • imgCSS: { width: 100 } - width is determined.

  • And that's it, demo works!!!

Sample code of HTML page for image preview

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="http://plugins.jquery.com/files/imgpreview.min.0.22.jquery.js.txt" 

type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function(){
$('ul#first a').imgPreview({
imgCSS: { width: 100 }
});
});
</script>
</head>

<body>
<ul id="first">
<li><a href='http://www.freefoto.com/images/15/10/15_10_70_thumb.jpg' rel="nofollow">The Sunset</a></li>
</ul>

</body>
</html>


To find more about imgPreview plugin visit page of it's creator James Padolsey.


Preview image for blogspot / blogger users


Blogger users should write all jscript code in one line or can call external javascript file .

For more information you can take a look at :


Sample of image preview working code in blogspot (in one line to avoid <br> tags):

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script><script src="http://plugins.jquery.com/files/imgpreview.min.0.22.jquery.js.txt" type="text/javascript"></script><script type="text/javascript">$(document).ready(function(){$('ul#first a').imgPreview({imgCSS: { width: 100 }});});</script><ul id="first"><li><a href='http://www.freefoto.com/images/15/10/15_10_70_thumb.jpg' rel="nofollow">The Sunset</a></li></ul>

Thursday, April 2, 2009

jQuery selectors samples

jQuery selectors are one of the most important part of jQuery. Their main purpose is to allow users to quickly and easily identify and manipulate any set of page elements.
The selector is a string expression that identifes the set of DOM elements that will be collected into a matched set to be operated upon by the jQuery methods (but we will focus on selectors). In this article you will find samples of using jQuery selectors.

Basics



#id

Matches a single element with the given id attribute.

Sample:

$('#SelectMe')

This selector select element with id SelectMe.

<p id="SelectMe" style="display:none">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>





element

Matches all elements with the given name.

Sample:

$("p")

This selector select all paragraph (p) elements.

<p id="SelectMe" style="display:none">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<button id="butSelect">Select</button>


For example if we call:

$("p").toggle();

both paragraphs will be toggled.




.class

Matches all elements with the given class.

Sample:

$(".testClass")

This selector select all elements with class testClass.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<button id="butSelect" class="testClass">Select</button>




*

Matches all elements.

Sample:

$("*")

Matches all elements.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<button id="butSelect" class="testClass">Select</button>





selector1, selector2, selectorN


Matches the combined results of all the specified selectors.

Sample:

$("#SelectMe, .testClass")

This selector select element with id #SelectMe and elements with class testClass.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<button id="butSelect" class="testClass">Select</button>



Hierarchy




ancestor descendant

Matches all descendant elements specified by "descendant" of elements specified by "ancestor".

Sample:

$("div p")


This selector select all paragraph (p) elements which are in div element.

<div id="divToSelect">
<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="testInput" />
</div>
<button id="butSelect" class="testClass">Select</button>



parent > child


Matches all child elements specified by "child" of elements specified by "parent".

Sample:

$("div > p")

This selector select all paragraph (p) elements which are in div element.

<div id="divToSelect">
<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="testInput" />
</div>
<button id="butSelect" class="testClass">Select</button>



prev + next

Matches all next elements specified by "next" that are next to elements specified by "prev".

Sample:

$("p + input")

This selector select all input elements which are next to paragraph element.

<div id="divToSelect">
<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="testInput" />
</div>
<button id="butSelect" class="testClass">Select</button>
<input id="noSelect" />




Selectors/siblings

Matches all sibling elements after the "prev" element that match the filtering "siblings" selector.

Sample:

$("#NotSelectMe ~ input")

This selector select all input elements after element with id NotSelectMe.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<input id="testInput" />
<p id="NotSelectMe">This paragraph will not be selected</p>

<input id="noSelect" />
<button id="butSelect" class="testClass">Select</button>



Basic filters



:first

Matches the first selected element.

Sample:

$("input:first")

This selector select first input element.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<input id="testInput" />
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="noSelect" />
<button id="butSelect" class="testClass">Select</button>



:last

Matches the last selected element.

Sample:

$("input:last")

This selector select last input element.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<input id="testInput" />
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="noSelect" />
<button id="butSelect" class="testClass">Select</button>



:not(selector)

Filters out all elements matching the given selector.

Sample:

$("input:not('#noSelect')")


This selector select all input element without element with id noSelect.

<p id="SelectMe" class="testClass">This paragraph will be selected</p>
<input id="testInput" />
<p id="NotSelectMe">This paragraph will not be selected</p>
<input id="noSelect" />
<button id="butSelect" class="testClass">Select</button>



:even

Matches even elements, zero-indexed.

Sample:

$("tr:even")

This selector select all even tr elements, zero-indexed.

<table border="1" class="style1">
<tr>
<td>
Row 0</td>
</tr>
<tr>
<td>
Row 1</td>
</tr>
<tr>
<td>
Row 2</td>
</tr>
<tr>
<td>
Row 3</td>
</tr>
</table>



:odd

Matches odd elements, zero-indexed.

Sample:

$("tr:odd")

This selector select all even tr elements, zero-indexed.

<table border="1" class="style1">
<tr>
<td>
Row 0</td>
</tr>
<tr>
<td>
Row 1</td>
</tr>
<tr>
<td>
Row 2</td>
</tr>
<tr>
<td>
Row 3</td>
</tr>
</table>



Related articles:
jQuery hello world
jQuery on blogspot (blogger) post
Basic web effect with jQuery


Tuesday, March 24, 2009

Basic web effect with jQuery

In this article you can find demos and sample code for basic effect functions in jQuery. We have: hide and show effect, fadeIn and fadeOut (disappearing) effect, slide down and slide up effect and animate effect. On my blog you can find more guides for cool javascript effects.

First you need to reference jQuery library (for more information see my first article about using jQuery.

Example:

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

Hide and show effect

Demo for show and hide function:




Code:
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#butShowHide').click(function()
{
$('#pShowHide').toggle();
});
});
</script>
<p id="pShowHide" style="display:none">This paragraph can be shown or hidden</p>
<button id="butShowHide">Show/Hide</button>


When butShowHide is clicked, toggle function is called on paragraph pShowHide.
Toggle function displaying matched elements. If they are shown, toggle makes them hidden. If they are hidden, toggle makes them shown.
There are also show and hide function. Toggle function is easier to use because you don't have to check if element is showed or hidden.




Demo for show and hide function with slow argument:



This div can be shown or hided slow


Code:
<script type="text/javascript">
$(document).ready(function(){
$("#butShowHideSlow").click(function () {

$("#divShowHideSlow").toggle("slow");
});
});
</script>
<button id="butShowHideSlow">Show and hide slowly</button>
<div style="width:300px;height:47px; border: solid 1px black;background-color:LightGrey;text-align:center;" id="divShowHideSlow">This div can be shown or hided slowly</div>


In this case we call toggle function with argument speed (toggle(speed)).
We set speed to slow.
Speed - A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).



FadeIn and FadeOut effect

Demo for fade in and fade out:

  

This paragraph can fade in and fade out


Code
<script type="text/javascript">
$(document).ready(function(){
$("#butFadeOut").click(function () {
$("#pFadeInOut").fadeOut(3000);
});

$("#butFadeIn").click(function () {
$("#pFadeInOut").fadeIn(3000);
});
});
</script>

<button id="butFadeOut">Fade Out</button>&nbsp;&nbsp;<button id="butFadeIn">Fade In</button>
<br />
<p id="pFadeInOut">This paragraph can fade in and fade out</p>



When button butFadeOut is clicked fadeOut function is called on paragraph pFadeInOut
fadeOut(3000) - fadeOut effect will run for 3 seconds.

When button butFadeIn is clicked fadeIn function is called on paragraph pFadeInOut.
fadeIn(3000) - fadeIn effect will run for 3 seconds.



Slide up and Slide down

Demo for slide up and slide down:



This toggle can be slide up and down


Code:
<script type="text/javascript">
$(document).ready(function(){
$('#butSlide').click(function () {
$('#divSlide').slideToggle("slow");
});
});
</script>

<button id="butSlide">Slide up/down</button>
<br />
<div style="width:300px;height:47px; border: solid 1px black;background-color:LightGrey;text-align:center;" id="divSlide">This toggle can be slide up and down</div>


When button butSlide is clicked slideToggle function is called on div divSlide with argument slow.

slideToggle(speed) - Toggle the visibility of all matched elements by adjusting their height.


Animate effect

Demo for animate:

   


This paragraph can move left and right




Code:

<script type="text/javascript">
$(document).ready(function(){
$("#butLeft").click(function () {
$("#pMovingParagraph").animate({"left": "-=50px", "opacity": 1}, 500);
});

$("#butRight").click(function () {
$("#pMovingParagraph").animate({"left": " =50px", "opacity": 1}, 500);
});
});
</script>

<button id="butLeft">move left</button>&nbsp;&nbsp;&nbsp;<button id="butRight">move right</button>


When button butLeft is clicked animate function is called on paragraph pMovingParagraph.

When button butRight is clicked animate function is called on paragraph pMovingParagraph.

animate( params, [duration])

params - A set of style attributes that you wish to animate, and to what end.

duration - A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).


Related articles:
jQuery hello world
jQuery on blogspot (blogger) post
jQuery selectors samples

Saturday, March 14, 2009

jQuery on blogspot (blogger) post

You find some cool jQuery features but don't know how to include jQuery code into your blogspot blog? Here you will find two steps needed to jQuery work on your blog.

Two steps for implement jQuery on blogspot post


  1. Reference jQuery library in your blogspot post

  2. To provide jQuery work you must reference jQuery library. One option is to reference on jquery-1.3.2.min.js file on google code.

    <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>


    Another option is to upload jquery library file somewhere on the web (look here for advices about uploading files for blogspot) and reference it on blogspot (on blogspot you can upload only images).


  3. jQuery code and style code should be in one line

  4. Example of jQuery code (in this form it will not function on blogger):

    <script type="text/javascript">
    $(function()
    {
    $("#butToggle").click(function()
    {
    $('#dvt').toggle(1000);
    });
    });
    </script>


    This jQuery code (above) should look like this to work on blogspot:

    <script type="text/javascript">$(function(){$("#butToggle").click(function(){$('#dvt').toggle(1000);});});</script>


    Example of style code (in this form it will not function on blogger):

    <style type="text/css">
    #dvt
    {
    width: 200px;
    height: 100px;
    border: solid 1px black;
    background-color:LightGrey;
    text-align:center;
    display:none;
    }
    </style>


    Style code should be like this to work on blogspot:






This demo show jQuery that works on blogger.When you click toggle button div is shown or hidden.

This works on blogger



And here is code needed for this demo that should be in blogspot post:

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){$("#butToggle").click(function(){$('#dvt').toggle(1000);});});</script>

<style type="text/css">#dvt{width: 200px;height: 100px;border: solid 1px black;background-color:LightGrey;text-align:center; display:none;}</style>

<div id="dvt">This works on blogger</div>
<button id="butToggle">Toggle</button>


Related articles:
Add javascript in blogspot (blogger) post
jQuery hello world
jQuery selectors samples

Tuesday, March 10, 2009

jQuery hello world

This text contain brief tutorial how to use jQuery on your web and have one demo and one short and simple example.

First let's see what is jQuery?
jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. jQuery is designed to change the way that you write Javascript.

To use jQuery you must have access to jQuery library. You can find jQuery library on http://jquery.com/. Choose production and download file.

jQuery download

To use jQuery you need to reference it on your page.

Example:

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

There is jquery-1.3.2.min.js file but the next version will have different name (probably jquery-1.3.3.min.js) so you will must change name of the file when there will be newer version. This work when you have Jquery library in same directory as your html page.

Another option is to reference jQuery library directly from google code.

Example:

<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>

Demo of disappearing paragraph with jQuery:


Example of Jquery, click paragraph
and it will fade away.



Code for disappearing paragraph with jQuery:


<html>
<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script>
(function(){
$("#paragraph1").click(function () {
$("#paragraph1").fadeOut("slow");
});

});
</script>
<style>
#paragraph1 { font-size:150%; cursor:pointer; }
</style>
</head>
<body>
<p id="paragraph1">
Example of Jquery, click paragraph
and it will fade away.
</p>
</body>
</html>


We have reference to jQuery library (see above for explanation)

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


There is paragraph with id paragraph1

<p id="paragraph1">
Example of Jquery, click paragraph
and it will fade away.
</p>



With this we determine style for element with id paragraph1.
<style>
#paragraph1 { font-size:150%; cursor:pointer; }
</style>



This code says :
when paragraph1 is clicked ( $("#paragraph1").click(function ())
then fadeOut method is called with parameter slow ($("#paragraph1").fadeOut("slow");).

<script>
(function(){
$("#paragraph1").click(function () {
$("#paragraph1").fadeOut("slow");
});
});
</script>


In the end paragraph disappear after user click on it. Instead parameter slow can stand normal or fast. Or time in miliseconds.

Related articles:
jQuery on blogspot (blogger) post
jQuery selectors samples
Basic web effect with jQuery