Home Web Front-end JS Tutorial Simple jQuery click water ripple animation example

Simple jQuery click water ripple animation example

Mar 08, 2018 am 11:35 AM
jquery fluctuation

This time I will bring you a simple jQuery click water ripple animation example. Use jQuery to create a click water ripple animation. What are the precautions? . Here is a practical case. Let’s take a look.

jQuery click water ripple animation principle:
1. Add <XXX class="ripple-wrapper"></XXX># to the tag that needs to achieve the water ripple effect. ## 2. The code will position the mouse relative to the label, and draw a circle with the mouse point as the center
3. The radius of the circle can be customized (the default is the maximum width or height of the label)
4. Dot color , and animation time, etc. You can modify the internal code by yourself, or directly call the $().css({}) method to overwrite
--Encapsulation example address: http://daxianshiyanshi.sinaapp.com/data/jsdata/2016 -4-8/ripplewrapperdemo1/index1.html
-- Unencapsulated example address: http://daxianshiyanshi.sinaapp.com/data/jsdata/2016-4-8/ripplewrapperdemo1/indexlod.html

$(function(){
   $(&quot;.ripple-wrapper&quot;).css(
       {
   &quot;position&quot;: &quot; absolute&quot;,
   &quot;top&quot;: &quot; 0&quot;,
   &quot;left&quot;: &quot; 0&quot;,
   &quot;z-index&quot;: &quot; 1&quot;,
   &quot;width&quot;: &quot; 100%&quot;,
   &quot;height&quot;: &quot; 100%&quot;,
   &quot;overflow&quot;: &quot; hidden&quot;,
   &quot;border-radius&quot;: &quot; inherit&quot;,
   &quot;pointer-events&quot;: &quot; none&quot;
   });
       $(&quot;.ripple-wrapper&quot;).parent().click(function(e){
          var ripple_obj=$(this).find(&quot;.ripple-wrapper&quot;);
          if(ripple_obj.find(&quot;div&quot;).length){ripple_obj.find(&quot;div&quot;).remove();}
          ripple_obj.prepend(&quot;&lt;div&gt;&lt;/div&gt;&quot;);
          var ripple_div=ripple_obj.find(&quot;div&quot;);
          ripple_div.css(
              {
   &quot;display&quot;: &quot; block&quot;,
   &quot;background&quot;: &quot; rgba(255, 255, 255, 0.7)&quot;,
   &quot;border-radius&quot;: &quot; 50%&quot;,
   &quot;position&quot;: &quot; absolute&quot;,
   &quot;-webkit-transform&quot;: &quot; scale(0)&quot;,
   &quot;transform&quot;: &quot; scale(0)&quot;,
   &quot;opacity&quot;: &quot; 1&quot;,
   &quot;transition&quot;: &quot; all 0.7s&quot;,
   &quot;-webkit-transition&quot;: &quot; all 0.7s&quot;,
   &quot;-moz-transition&quot;: &quot; all 0.7s&quot;,
   &quot;-o-transition&quot;: &quot; all 0.7s&quot;,
   &quot;z-index&quot;: &quot; 1&quot;,
   &quot;overflow&quot;: &quot; hidden&quot;,
   &quot;pointer-events&quot;: &quot; none&quot;
       });
          var R=  parseInt(ripple_obj.outerWidth());/*默认半径为ripple-wrapper宽*/
          if(parseInt(ripple_obj.outerWidth())&lt;parseInt(ripple_obj.outerHeight())){
                 R=  parseInt(ripple_obj.outerHeight());/*如果高度大于宽半径为ripp,le-wrapper高*/
          }
           ripple_div.css({&quot;width&quot;:(R*2)+&quot;px&quot;,&quot;height&quot;:(R*2)+&quot;px&quot;,&quot;top&quot;: (e.pageY -ripple_obj.offset().top - R)+&#39;px&#39;, &quot;left&quot;: ( e.pageX -ripple_obj.offset().left -R)+&#39;px&#39;,&quot;transform&quot;:&quot;scale(1)&quot;, &quot;-webkit-transform&quot;:&quot;scale(1)&quot;,&quot;opacity&quot;:&quot;0&quot;});;
       });
        
       });
&lt;!DOCTYPE html&gt;
&lt;html&gt;
 
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;title&gt;Document&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;ripple-wrapper.js&quot;&gt;&lt;/script&gt;
    &lt;style&gt;
        .ck {
            cursor: pointer;
            display: block;
            padding: 1em;
            text-decoration: none;
            width: 200px;
            height: 20px;
            position: relative;
            overflow: hidden;
            color: #fff;
        }
    &lt;/style&gt;
&lt;/head&gt;
 
&lt;body  &gt;
    &lt;div class=&quot;ck&quot; style=&quot;background: #5f5f5f&quot;&gt;
        点一下
        &lt;div class=&quot;ripple-wrapper&quot;&gt;&lt;/div&gt;
    &lt;/div&gt; 
&lt;/body&gt;
 
&lt;/html&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
 
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
    &lt;title&gt;Document&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;
    &lt;style&gt;
        .ck {
            background: #ffab91;
      
            display: block;
            padding: 1em;
            text-decoration: none;
            width: 200px;
            height: 20px;
            position: relative;
            overflow: hidden;
        }
         
        .ck .bd {
            background: rgba(0, 0, 0,0.8);
            border-radius: 50%;
            width: 0px;
            height: 0px;
            position: absolute;
             -webkit-transform: scale(0);
             transform: scale(0);
             opacity: 1;
        }
         
        .dh {
            animation: ldm 0.8s  ;
            -moz-animation: ldm 0.8s ;
            -o-animation: ldm 0.8s ;
            -webkit-animation: ldm 0.8s   ;
        }
         
        @-webkit-keyframes ldm {
            100% {
                -webkit-transform:  scale(1);
                opacity: 0
            }
        }
         
        @keyframes ldm {
             100% {
                -webkit-transform:  scale(1);
                opacity: 0
            }
        }
    &lt;/style&gt;
&lt;/head&gt;
 
&lt;body style=&quot; background: #aaab91;&quot;&gt;
    &lt;div class=&quot;ck&quot;&gt;
        &lt;span class=&quot;bd&quot;&gt;&lt;/span&gt; adasdsd
    &lt;/div&gt;
    &lt;script&gt;
        $(&quot;.ck&quot;).click(function(e){
             $(this).find(&quot;.bd&quot;).removeClass(&quot;dh&quot;);
            var R=6;
           R= parseInt($(this).outerWidth());
           if(parseInt($(this).outerWidth())&lt;parseInt($(this).outerHeight())){
               R=  parseInt($(this).outerHeight());
           }
           $(this).find(&quot;.bd&quot;).css({&quot;width&quot;:(R*2)+&quot;px&quot;,&quot;height&quot;:(R*2)+&quot;px&quot;});
        $(this).find(&quot;.bd&quot;).css({&quot;left&quot;:(e.pageX-$(this).position().left-R)+&quot;px&quot;,&quot;top&quot;:(e.pageY-$(this).position().top-R)+&quot;px&quot; });
        // $(this).find(&quot;.bd&quot;).css({&quot;left&quot;:(e.pageX-$(this).position().left-R/2 )+&quot;px&quot;,&quot;top&quot;:(e.pageY-$(this).position().top-R/2  )+&quot;px&quot; });
        $(this).find(&quot;.bd&quot;).addClass(&quot;dh&quot;);
        });
    &lt;/script&gt;
&lt;/body&gt;
 
&lt;/html&gt;
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!


Related reading:

Simple image click upload function

The text in ionic app cannot be copied by long pressing , How to paste

The above is the detailed content of Simple jQuery click water ripple animation example. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute?

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

Summary of commonly used file operation functions in PHP

See all articles