Jquery learning notes-jQuery implements click and mouse event sensing, jquery-jquery

Source: Internet
Author: User

Jquery learning notes-jQuery implements click and mouse event sensing, jquery-jquery

For click events, jQuery also provides a dynamically alternating toggle () method. This method accepts two parameters, both of which are listener functions and are used in the click events.

Example: Dynamic Interaction of click events.

<script type="text/javascript">            $(function() {                $("#ddd").toggle(                    function(oEvent) {                        $(oEvent.target).css("opacity", "0.5");                    },                    function(oEvent) {                        $(oEvent.target).css("opacity", "1.0");                    }                );            });        </script>        <div id="ddd">11</div>

2. Implement mouse sensing

In css, you can use the hover pseudo class to implement style revisions to implement separate css styles. After jQuery is introduced, almost all elements can use hover () to sense the mouse. In addition, more complex effects can be created. In essence, it is the combination of mouseover and mouseout events.
The hover (over, out) method can accept two parameters, both of which are functions. The first is triggered by moving the mouse over the element, and the second is triggered when the mouse is removed from the element.

<Script type = "text/javascript"> $ (function () {$ ("# ddd "). hover (function (oEvent) {// The first function is equivalent to listening for a mouseover event (oevent.target).css ("opacity", "0.5") ;}, function (oEvent) {// The second function is equivalent to listening for the mouseover event (oevent.target).css ("opacity", "1.0 ");});}); </script> <div id = "ddd"> 11 </div>

Compared with the first example, toggle () is replaced with hover ().

 

Under the guidance of wenzi0_0, write a few small examples of toggle ().

1. Regular applications

<script type="text/javascript">            $(function() {                $("#ddd").click(function(){                $("#eee").toggle();                    });            });        </script>        <div id="ddd">11</div>        <div id="eee">122</div>

2.css attributes

<script type="text/javascript">            $(function(){                $("#eee").toggle(function() {                        $("#ddd").css("background-color", "green");                    },                    function() {                        $("#ddd").css("background-color", "red");                    },                    function() {                        $("#ddd").css("background-color", "yellow");                    }                );            });        </script>        <div id="ddd">11</div>        <div id="eee">122</div>

 

It is not easy to write a blog. You are welcome to give comments for encouragement. Sharing is a pleasure! You are welcome to shoot bricks and likes. (JavaScript, ajax, and jQuery articles are constantly updated. Follow me to stay updated)

Other highlights

JQuery tutorial (29)-jQuery plug-in development-Specify parameters for plug-in Methods jQuery tutorial (28)-jQuery plug-in development-jQuery tutorial (27) -jQueryajax-Modify default options jQuery tutorial (26)-ajax-use JSONP to load Remote Data jQuery tutorial (25)-security restrictions on ajax operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.