jQuery Effect - slide - CodingTuting


jQuery Effect - slide


CodingTuting

This is the example of the jQuery slideToggle() method. Learn jQuery with jQuery Tutorial at CodingTuting.Com. You'll find more jQuery Tutorials on this site.

jQuery slide effect is used to slide up and slide down the content.

There are 3 kinds of slide effect are in jQuery.

  1. slideDown()
  2. slideUp()
  3. slideToggle()

1)   slideDown()

The jQuery effect "slideDown()" is used to slide down the content.

Syntax:

$(selector).slideDown(speed, callback);

slideDown() methods has two optional parameters:-

1. The parameter "speed" is used to change the speed of slide. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the slideDown() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will slide down the text after a click on the button.

Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideDown() method. You'll find more jQuery Tutorials on this site.



Code


<head>

    <style> 
        #slideBox
        {
            padding: 5px;
            text-align: center;
            background-color: #3b3e48;
            border: solid 1px #c3c3c3;
        }

        #slideBox 
        {
            padding: 50px;
            display: none;
        }
    </style>

</head>

<body>
 
    <button id="slideDown-btn">Slide Down</button>

    <div id="slideBox">
        <p>Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideDown() method. You'll find more jQuery Tutorials on this site.</p>
    </div>

</body>

Add this jQuery before closing the </body> tag

    <script> 
        $(document).ready(function(){
            $("#slideDown-btn").click(function(){
                $("#slideBox").slideDown("slow");
           });
        });
    </script>


2)   slideUp()

The jQuery effect "slideUp()" is used to slide up the content.

Syntax:

$(selector).slideUp(speed, callback);

slideUp() methods has two optional parameters:-

1. The parameter "speed" is used to change the speed of slide up. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the slideUp() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will slide up the text after a click on the button.

Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideUp() method. You'll find more jQuery Tutorials on this site.



Code


<head>

    <style> 
        #slideUpBox
        {
            padding: 5px;
            text-align: center;
            background-color: #3b3e48;
            border: solid 1px #c3c3c3;
        }

        #slideUpBox 
        {
            padding: 50px;
        }
    </style>

</head>

<body>
 
    <button id="slideUp-btn">slide up</button>

    <div id="slideUpBox">
        <p>Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideUp() method. You'll find more jQuery Tutorials on this site.</p>
    </div>

</body>

Add this jQuery before closing the </body> tag

    <script> 
        $(document).ready(function(){
            $("#slideUp-btn").click(function(){
                $("#slideUpBox").slideUp("slow");
           });
        });
    </script>


3)   slideToggle()


jQuery slideToggle effect
jQuery slideToggle() Effect | jQuery Tutorial | CodingTuting

The jQuery effect "slideToggle()" is used to switching in slideUp and the slideDown methods.

Syntax:

$(selector).slideToggle(speed, callback);

slideToggle() methods has two optional parameters:-

1. The parameter "speed" is used to change the speed of toggle effect. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the slideToggle() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will toggle (switch) between slide up and slide down effect on the element after a click on the button.

Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideToggle() method. You'll find more jQuery Tutorials on this site.



Code


<head>

    <style> 
        #slideToggleBox
        {
            padding: 5px;
            text-align: center;
            background-color: #3b3e48;
            border: solid 1px #c3c3c3;
            display:none;
        }

        #slideToggleBox 
        {
            padding: 50px;
        }
    </style>

</head>

<body>
 
    <button id="slideToggle-btn">Slide Toggle</button>

    <div id="slideToggleBox">
        <p>Learn jQuery with jQuery Tutorial at CodingTuting.Com. This is the example of the jQuery slideToggle() method. You'll find more jQuery Tutorials on this site.</p>
    </div>

</body>

Add this jQuery before closing the </body> tag

    <script> 
        $(document).ready(function(){
            $("#slideToggle-btn").click(function(){
                $("#slideToggleBox").slideToggle("slow");
           });
        });
    </script>

Thanks for Reading


Create Scroll to Top Button jQuery ScrollTop - CodingTuting


How to Create back to Top Button in our Website?

Scroll Button Back to Top is very important for a website. It gives a very good user interface, and the user doesn't need to too much scroll to go to the top of the page.

Go to top Scrolltop button in jQuery HTML
Add jQuery ScrollTop & Scroll button top | CodingTuting | Image By mmi9 from Pixabay

Here we have a very simple method to add Scroll Top button our website.

We will make a back-to-top button using HTML, CSS, and jQuery. We'll use "jQuery scrollTop()" method for this. It is very easy.

Follow the below step to create a "scroll to top jquery"


Step 1
Create a scroll-top button at the bottom of the page
<button id="top-btn"> Top </button>

You can use any icon or symbol instead of the button text "Top"


Step 2

Add CSS to give style to the Scroll-Top button

<style>
 
    html 
    {
        scroll-behavior: smooth; /*Mandatory for smooth scroll*/
    }
  
    #top-btn
    {
        position: fixed; /* Mandatory */
        right: 20px; /* Mandatory */
        bottom: 20px; /* Mandatory */
        padding: 9px; /* Mandatory */
        border-radius: 5px;
        color: #fff;
        background-color: #5089b9;
        border: none;
        display:none;
    }
 
    button#top-btn:hover
    {
        background-color: #2978bb;
    }

</style>

You can modify the style of the button according to your website theme.


Step 3

Add jQuery before closing the </body> tag

<script data-src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script>

Note - Don't add jQuery again if you've added already.



Step 4

Add this jQuery code before closing the </body> tag

$(document).ready(function(){
  
    $(window).scroll(function(){
  
        if($(this).scrollTop() >= 500) /* Set limit according to your need */
        {
            $("#top-btn").fadeIn();
     
            $("#top-btn").click(function(){
                $(window).scrollTop(0);
            });
         }
         
         else
         {
             $("#top-btn").fadeOut();
         }    
    });  
  
});





Thanks for Reading


jQuery Effect Fade - CodingTuting


jQuery Effect - Fade


jQuery effect fadein, fadeout, fadetoggle, fadeto
jQuery Effect jQuery Tutorial CodigTuting

The jQuery "Fade" Effect is used to appear and disappear the visibility. It applies the opacity on the element.

jQuery has 4 types of Fade Effect:-

  1. fadeIn()
  2. fadeOut()
  3. fadeToggle()
  4. fadeTo()

1)   jQuery fadeIn()

The jQuery fadeIn() method is use to appear (fade) in the hidden content.

Syntax:

$(selector).fadeIn(speed, callback);

fadeIn() methods has two optional parameters.

1. The parameter "speed" is used to change the default speed of Show (Fade). The default is 400. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the fadeIn() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will appear the color strips after a click on the button.

    
    <button class="fadeIn-btn"> FadeIn </button>


    <div id="fadeIn-strip1" style="width:300px;height:20px;display:none;background-color:red;"></div> <br/>
    <div id="fadeIn-strip2" style="width:300px;height:20px;display:none;background-color:green;"></div> <br/>
    <div id="fadeIn-strip3" style="width:300px;height:20px;display:none;background-color:blue;"></div> <br/>
    <div id="fadeIn-strip4" style="width:300px;height:20px;display:none;background-color:yellow;"></div>

$(document).ready(function(){
    $(".fadeIn-btn").click(function(){
        $("#fadeIn-strip1").fadeIn(); // default speed 400
        $("#fadeIn-strip2").fadeIn("fast");
        $("#fadeIn-strip3").fadeIn("slow");
        $("#fadeIn-strip4").fadeIn(3000);
    });
 });

Output:








2)   jQuery fadeOut()

The jQuery fadeOut() method is use to disappear (display none) the visible content.

Syntax:

$(selector).fadeOut(speed, callback);

fadeOut() methods has two optional parameters.

1. The parameter "speed" is used to change the default speed of Hiding. The default speed is 400. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the fadeOut() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will disappear the color strips after a click on the button.

    
    <button class="fadeOut-btn"> fadeOut </button>


    <div id="fadeOut-strip1" style="width:300px;height:20px;background-color:red;"></div> <br/>
    <div id="fadeOut-strip2" style="width:300px;height:20px;background-color:green;"></div> <br/>
    <div id="fadeOut-strip3" style="width:300px;height:20px;background-color:blue;"></div> <br/>
    <div id="fadeOut-strip4" style="width:300px;height:20px;background-color:yellow;"></div>


$(document).ready(function(){
    $(".fadeOut-btn").click(function(){
        $("#fadeOut-strip1").fadeOut(); // default speed 400
        $("#fadeOut-strip2").fadeOut("fast");
        $("#fadeOut-strip3").fadeOut("slow");
        $("#fadeOut-strip4").fadeOut(3000);
    });
 });

Output:








3)   jQuery fadeToggle()

The jQuery fadeToggle() method is use to switching between fadeIn and fadeOut effect. Like switch on-off the bulb. One electricity swtich can switch on and off the bulb.

Syntax:

$(selector).fadeToggle(speed, callback);

fadeToggle() methods has two optional parameters.

1. The parameter "speed" is used to change the default speed of effect. The default is 400. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the fadeToggle() method completed. We'll learn about callback in the upcoming chapter.



Example:

This will switch (show and hide) the color strips after a click on the button.

    
    <button class="fadeToggle-btn"> fadeToggle </button>


    <div id="fadeToggle-strip1" style="width:300px;height:20px;background-color:red;"></div> <br/>
    <div id="fadeToggle-strip2" style="width:300px;height:20px;background-color:green;"></div> <br/>
    <div id="fadeToggle-strip3" style="width:300px;height:20px;background-color:blue;"></div> <br/>
    <div id="fadeToggle-strip4" style="width:300px;height:20px;background-color:yellow;"></div>

$(document).ready(function(){
    $(".fadeToggle-btn").click(function(){
        $("#fadeToggle-strip1").fadeToggle(); // default speed 400
        $("#fadeToggle-strip2").fadeToggle("fast");
        $("#fadeToggle-strip3").fadeToggle("slow");
        $("#fadeToggle-strip4").fadeToggle(3000);
    });
 });

Output:








4)   jQuery fadeTo()

The jQuery fadeTo() method is use to apply the animated opacity to the element. The value of opacity is 0 to 1

Syntax:

$(selector).fadeTo(speed, opacity, callback);

fadeTo() methods has three optional parameters.

1. The parameter "speed" is used to change the default speed of opacity effect. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "opacity" is the value of opacity, which should be 0 To 1. Like 0.5, 0.9, 0.75 etc.

3. The parameter "callback" is a function, which executes after the fadeTo() method completed. We'll learn about callback in the upcoming chapter.

Example:

This will apply the opacity to the strips after a click on the button.

    
    <button class="fadeTo-btn"> fadeTo </button>


    <div id="fadeTo-strip1" style="width:300px;height:20px;background-color:red;"></div> <br/>
    <div id="fadeTo-strip2" style="width:300px;height:20px;background-color:green;"></div> <br/>
    <div id="fadeTo-strip3" style="width:300px;height:20px;background-color:blue;"></div> <br/>


$(document).ready(function(){
    $(".fadeTo-btn").click(function(){
        $("#fadeTo-strip1").fadeTo("fast", 0.4);
        $("#fadeTo-strip2").fadeTo("slow", 0.65);
        $("#fadeTo-strip3").fadeTo("slow", 1);
    });
 });

Output:







Thanks for Reading


jQuery Effect - Toggle - CodingTuting


jQuery Effect - Toggle


jQuery toggle class jquery, toggle() effect
jQuery Effect jQuery Tutorial CodingTuting

Toggle means "Switching".

jQuery Toggle effect is one of the most useful effects.
Toggle effect is used to switching between Hide and Show effects. Like On-Off switch. Here we will see jquery toggle for hide and show.

In other words, we can understand that - jquery toggle works with visibility. Whenever we want to modify the visibility (visibility true or visibility false), we should use the jquery toggle visibility. In this jquery tutorial we'll see how jquery toggle works?


Syntax:

$(selector).toggle(speed, callback);

Both Hide() and Show() methods have two optional parameters.

1. The parameter "speed" is used to change the default speed of Hiding and Showing. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the Hide/Show method completed. We'll learn about callback in the upcoming chapter.

Example:

This will Hide and Show the element <p>

    <button class="hide-show-btn">Text Hide Show</button>

    <p> This is an example text. Click on the above button to Hide and Show this text. </p>
 
$(document).ready(function(){   
    $(".hide-show-btn").click(function(){
        $("p").toggle();
    });
});


Output


This is an example text. Click on the above button to Hide and Show this text.


You may like more in jQuery


jQuery toggle effect is also used for toggle the 'class'. Any kind of task like 'switching' can be done by using the jquery toggle effect.

Let's see How to use jquery toggle class


jQuery toggle class


Click on the above button to add class "bgParaChange" for change the background color.


Here is the Code and method of above jQuery toggle class example.

For toggle class in jquery -

Step 1 - We'll create a class - name "bgParaChange", and give it style for change the background color.




    <style>
        .bgParaChange
        {
            background-color:dimgray;
        }
    </style>


Step 2 - Create a button and give it a class or id for selecting it. And create a paragraph in HTML and give it a class or id for selecting it.

    <button class="btntoggleClass">Toggle Class</button>

    <p class="bgPara"> Click on the above button to add class "bgParaChange" for change the background color. </p>

Step 3 - Create a jquery function, which will occur on click button. This function will toggle the class "bgParaChange" on specific element where we want.

 
$(document).ready(function(){  
   $(".btntoggleClass").click(function(){
       $(".bgPara").toggleClass("bgParaChange");
    });
});


This is the simple example of jquery toggle visibility


We hope you understand that how jquery toggle works and how to toggle jquery. Hope you like this short tutorial with example of how to use jquery toggle and jquery toggle class. This is one of the very useful effect of jQuery.

Stay connected with the site CodingTuting for more interesting topics with example.
We would like your suggestion about any topic or solution.

This same toggle effect use in jquery slide toggle. click here to see how to use jquery slide toggle.


Thanks for Reading


jQuery Hide Show


jQuery Effect - Hide and Show


jQuery Hide and Show Effect
jQuery Hide Show Effect jQuery Tutorial CodingTuting

Syntax:

$(selector).hide(speed, callback);

$(selector).show(speed, callback);

Both Hide() and Show() methods have two optional parameters.

1. The parameter "speed" is used to change the default speed of Hiding and Showing. The value of the "speed" parameter can be: "slow", "fast", or in milliseconds.

2. The parameter "callback" is a function, which executes after the Hide/Show method completed. We'll learn about callback in the upcoming chapter.


1)   jQuery Hide()

jQuery Hide() Method is use to hide the HTML element.


Example:

This will hide the element <p>

 <button class="eg-button">Text Hide</button>

 <p> This is an example text. Click on the above button to hide this text. </p>
  
 $(document).ready(function(){
     $(".eg-button").click(function(){
         $("p").hide();
     });
 });
 

Output:


This is an example text. Click on the above button to hide this text.


2)   jQuery Show()

jQuery show() Method is use to show the hide HTML element.


Example:

This will show the hide the element <p>

    <button class="show-btn">Text Show</button>

    <p> This is an example text. Click on the above button to show this text. </p>
 
$(document).ready(function(){
    $("p").hide();
   
    $(".show-btn").click(function(){
        $("p").show();
    });
});


Output:


This is an example text. Click on the above button to show this text.


Thanks for Reading


jQuery Selectors - jQuery Tutorial CodingTuting


jQuery Selectors


Use of jQuery selectors
jQuery Selectors jQuery Tutorial CodingTuting.com

We have to tell to the jQuery that - on which part or on which element we want to apply any action. We use the "selector" for this. We'll look for "How to use jQuery Selectors" in this jQuery Tutorial.

jQuery selectors are used to selecting the HTML element.

And jQuery Selectors are based on HTML Tag Name, ID, Class Name, attributes, the value of the attributes, etc.

Selectors are written in the parentheses with the $ sign. $(selector)


Select by .class

Write classname with the prefix. (dot) in the quotes.

Syntax:

$(".className")

Example:

 $(".testClass")
 $(".myClass")
 $(".darkMode")

Practical

This will hide the content of the class "hideText".

 

 

This is an example text. Click above button to hide this text.



Output:


This is an example text. Click above button to hide this text.



Select by #id

Write id with prefix # (hash) in the quotes.

Syntax:

$("#id")

Example:

 $("#testId")
 $("#myId")
 $("#fName")

Practical

This will hide the content of the id "hideId".

    

    

This is an example text. Click above button to hide this text.

    

Output:


This is an example text. Click above button to hide this text.



Select HTML element

Write tag name in the quotes.

Syntax:

$("tag name")

Example:

        $("span")
        $("p")
        $("ul")
    

Practical

This will hide the content of the "span" tag.

    

    
        This is an example text in a span tag. Click above button to hide this text. 
    
    

Output:


This is an example text in a span tag. Click above button to hide this text.

Thanks for Reading


jQuery Syntax - CodingTuting


jQuery Basic Syntax
jQuery Syntax jQuery Tutorial CodingTuting.Com

Rules of jQuery
jQuery has only 2 rules -
  1. Initialize the jQuery
  2. Use the jQuery
The jQuery is perform well after the page is fully loaded. Because a web page can't be manipulated well without fully loaded.

1. Initialize the jQuery

    $(document).ready(function(){
        // Your Code
    });
jQuery first determine that the page (DOM) is fully loaded or not. The code under the above event function will executed only after the page (DOM) is fully loaded/ready.
jQuery has provided the alternate and shorter method of above event function. This is mostly use by the experienced developers.

$(function(){
    // Your Code
});

You can use any of the above event function for initialize the jQuery. But it is good practice to use the first one.


2. Use the jQuery

Syntax:
    $(selector).action();
The $ sign is use to access the jQuery.
selector is use to select the appropriate HTML element.
action() is the task which we want to perform.
Example:
    $(this).toggle();
    $("p").hide();
    $(".myClass").show();
    $("#myId").hide();
We will understand above all kinds of example in upcoming sections.


This is the syntax of a complete jQuery task

    $(document).ready(function(){
        $(selector).action();
    });

or

$(function(){
    $(selector).action();
});

We hope you got the basic syntax of the jQuery.
Please ask question in comment if you've any query.

Please share this article for support our website CodingTuting.Com


Thanks for Reading




Installation of jQuery - CodingTuting


How to Install and use jQuery ?


jQuery installation
jQuery Installation CodingTuting. Image by aji argo putro from Pixabay

There are two ways to use jQuery on our website
  1. We can download the jQuery Library from jQuery.com
  2. Add jQuery CDN (Content Delivery Network) on your website.

1. Download the jQuery Library

There are two kinds of copies are available for downloading.
  1. Compressed/Production Copy: This copy is used for the live website. It is compressed and saves bandwidth. It gives a good performance.
  2. Uncompressed/Development Copy: This copy is used for development or debugging/testing.

Download both copies from here Download jQuery

Add jQuery on your website after download

The best of adding the jQuery is to place it before the closing </body> Tag.
<html>
    <head>
        <title> jQuery Tutorial - CodingTuting </title>
    </head>

    <body>
        <script src="folder_path/jquery-3.3.1.min.js"></script>
    </body>
</html>


2. Use jQuery CDN

We can add jQuery without downloading it, by using CDN (Content Delivery Network).
We can get jQuery CDN from either Google or Microsoft.

CDN (Content Delivery Network): It is a distribution network. The goel of this network is to provide the content or data to the user based on the geographic location. The speed of this network is faster than the user's own server.


Google's CDN version 3.3.1

Add Google CDN before the closing </body> Tag.
<html>
    <head>
        <title> jQuery Tutorial - CodingTuting </title>
    </head>

    <body>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </body>
</html>



Microsoft CDN version 3.3.1

Add Microsoft CDN before the closing </body> Tag.
<html>
    <head>
        <title> jQuery Tutorial - CodingTuting </title>
    </head>

    <body>
        <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
    </body>
</html>


You can download more versions of CDN from this Microsoft Link



jQuery Overview - CodingTuting


jQuery Overview | Understand the jQuery


What is jQuery ?

jQuery is a simple and fastly execute "JavaScript Library".

jQuery supports the syntax of  JavaScript. The purpose of the jQuery is to simplify and make fast to the JavaScript. Because jQuery's syntaxes are very easy to understand, so we can do easily JavaScript programming by using jQuery.

jQuery requires less code. That's why it is known as - "Write Less Do More".

jQuery tutorial overview
jQuery Tutorial Overview CodingTuting


What we can do using jQuery ?

We can do following tasks very easily using jQuery.

  • Manipulate HTML elements and traversing the DOM.
  • Event handling.
  • Animate the Web Page.
  • Dynamically change the content and the behavior of the Web Page.
  • We can add our own effects and creativity.
  • Use of AJAX. And more.


Prerequisites for jQuery

Before starting to learn jQuery, You have basic knowledge of:
  • HTML
  • CSS
  • JavaScript




jQuery Tutorial - CodingTuting

jQuery Tutorial | Learn jQuery with Best and Easy Example

Learn jQuery from zero to advance with easy tutorials and examples at CodingTuting.com. Also, get jQuery CDN.

Learn jquery with jquery tutorial
Learn jQuery at CodingTuting.comImage Source


  • In simple - jQuery is a JavaScript Library.
  • jQuery very simplifies JavaScript.
  • jQuery is lightweight and quickly executes.
  • jQuery is very easy to understand.


Example of jQuery


This is an example text. It'll hide and show.





More in jQuery