Code Monkey home page Code Monkey logo

jquery.ripples's Introduction

jQuery Ripples Plugin

By the powers of WebGL, add a layer of water to your HTML elements which will ripple by cursor interaction!

Important: this plugin requires the WebGL extension OES_texture_float (and OES_texture_float_linear for a better effect) and works only with same-origin images (see this link for more information on using cross-origin requested images).

Click here for a demo and to see how to use it.

Usage

Include the script at the end of your page after including jQuery, or when you are using bundling tools such as Webpack or Browserify, simply import it into your bundle.

The quickest way to use this plugin on an element is to ensure that the element has a background-image set (currently only URLs are supported), then initialize the plugin as follows:

$(selector).ripples();

Optionally you can tweak the behavior and appearance by initializing it with options (See the options secton for the full list of options):

$(selector).ripples({
  dropRadius: ...,
  perturbance: ...,
  ...
});

The plugin also has several methods to programmatically add drops, show, hide or remove the effects among other things. See the methods section for more details.

Options

Name Type Default Description
imageUrl string null The URL of the image to use as the background. If absent the plugin will attempt to use the value of the computed background-image CSS property instead. Data-URIs are accepted as well.
dropRadius float 20 The size (in pixels) of the drop that results by clicking or moving the mouse over the canvas.
perturbance float 0.03 Basically the amount of refraction caused by a ripple. 0 means there is no refraction.
resolution integer 256 The width and height of the WebGL texture to render to. The larger this value, the smoother the rendering and the slower the ripples will propagate.
interactive bool true Whether mouse clicks and mouse movement triggers the effect.
crossOrigin string "" The crossOrigin attribute to use for the affected image. For more information see MDN.

Methods

drop

Call $(selector).ripples('drop', x, y, radius, strength) to manually add a drop at the element's relative coordinates (x, y). radius controls the drop's size and strength the amplitude of the resulting ripple.

destroy

Call $(selector).ripples('destroy') to remove the effect from the element.

hide / show

Call .ripples('hide') and .ripples('show') to toggle the effect's visibility. Hiding it will also effectively pause the simulation.

pause / play

Call $(selector).ripples('pause') and .ripples('play') to toggle the simulation's state.

set

Call $(selector).ripples('set', name, value) to update properties of the effect. The properties that can be updated are:

  • dropRadius
  • perturbance
  • interactive
  • imageUrl (setting the image URL will update the background image used for the effect, but the background-image CSS property will be untouched)
  • crossOrigin (setting this won't have any effect until imageUrl is changed)

updateSize

The effect resizes automatically when the width or height of the window changes. When the dimensions of the element changes, you need to call $(selector).ripples('updateSize') to update the size of the effect accordingly.

jquery.ripples's People

Contributors

sirxemic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.ripples's Issues

webGL on mobile

Is there a reason why this effect doesn't work on mobile? Looking at webGL support, and it looks like chrome on phones should be able to render the effect, but for some reason it isn't.

How to add ripples programatically ?

I've tried this, but it doesn't work.

$('#add').on('click', function(e){
e.preventDefault();
$('#test').ripples("drop", 200, 200, 20, 0.04);
})

Chrome Ripple Effect

Internet Explorer and Firefox display really amazing Ripple Effects
But the same code doesn't create that kind of effect in Chrome.
Any idea, why that's happening?

can work ripples in plain divs?

Hello!
I try to make ripples on div id

i.e in your demo
html

<div id="fold"></div>

css

main, #fold {
    display: inline-block;
    vertical-align: middle;
    background: url(img/bg.jpg);
    padding:  100px;
    max-width: 500px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

js

        $('#fold').ripples({
            resolution: 128,
            dropRadius: 10, //px
            perturbance: 0.04,
            interactive: false
        });

but ripples not appear
any idea?

Problem with backgrond-position in IE 11

Steps to reproduce

edit index.html in source file

main {
    background: url(img/bg.jpg) no-repeat center center; /* that's fine */
}

It doen't work when change background-position to center top:

main {
    background: url(img/bg.jpg) no-repeat center top;
}

Any way of running without `OES_texture_float`?

I'm using Qt 5.5.0 Canvas3D and am wondering if there is a way for ripples texture to use gl.UNSIGNED_BYTE instead of gl.FLOAT. My attempts at doing that were unsuccessful, and I'm having a hard time, because I'm just beginning with GLSL and WebGL. Any suggestions how to tackle that problem?

Console Error in Chrome

showing console error in chrome browser :-
"Access to Image at 'file:///E:/Themeix/HTML5/SPA%20Beauty%20Care%20Html%20Template/preview/images/header-bg.jpg' from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access."

How to change the circle ripple into ellipse ripple

Hey, I'am working on a program that mainly focus on how to use some animation effect to display the rhythm of a music. The effect is shown below.
qq 20150801144827
The ellipse will diffuse like the ripple. I want to add your effect to my project, but I'm a beginner on programming and just knowing a few things about javascript, html5 and d3.js (nothing about webgl).
Can you tell me how to change the shape of the ripple?

You can also contact me by sending a email to [email protected].
Thank you very much!

Internet Explorer Issue

Hi, I'm using your jquery ripples effect on a pool service website here: www.holidaypoolservice.ca and am currently having problems in Internet Explorer 11.

I’ve tried the website on all of our computers at work and my computer at home (all of which have auto-updates for IE) and the animation goes blank to a white colour after a quick flash. I’ve checked and it seems like everything is updated and installed (javascript, etc.).

Please advise if this is a bug and what can be done. Thanks.

Interactive

Hello, I am set parameter interactive false, but ripple still work on mousemove...(sorry for my bad English)

cross-origin whilst testing on local machine

I haven't tested it on a live environment but, whilst testing on my local machine it gave me an error concerning cross-origin image loading.

found the culprit
line 133: image.src = backgroundUrl;

tilt

yeah, this is more like a feature request.
is there a way to tilt the the entire ripple effect?
so let's say i've got this image of a lake
jenks_lake
now i only want the effect on the water obviously. i can do that if i overlay the same image with the water cut out. then the effect is only visible on the water. but still it will look wrong cause it's not tilted. any easy win on this?

[Feature request] canvas element created by this library should also have user-defined CSS class

Firstly, thanks a lot for this library, very helpful.
This library creates canvas element for water ripple effect, right? I am creating ripple effect on body element, sometimes due to DOM manipulation inside body element, scroll bar appears and disappears on body element. If the page loads with scroll bar on body and after deleting some elements in body scroll bar disappears because of less space required by remaining element. Because of which there appears a blank space on the left where scroll bar occupied space then.
I can fix it by setting canvas: width:100% but this can be messy hack if there were more than one canvas element on my page.

This gif to explain what I meant: https://i.imgur.com/XqdLRNR.gifv Dark blue color is the color of background on body along with background image

So my request is that your library should set some custom user-defined CSS selector which can be used in this type of situation...
Thanks

Mac:Safari CrossOrigin Error

If background-image is base64 image, crossOrigin error in Safari of Mac OS.

Needs to change in 176 line.
image.crossOrigin = null;

with background-image set, image is being requested twice

I am setting ripples effect on body and setting background-image on the same using in CSS file.
But I am observing that the image is being requested twice in network tab of chrome devtools. First time it is requested by html document via css (of course) and second one is being requested by ripples.js.
I don't think this is a good thing, requesting same file twice at same time could slow the webpage loading, right?
Should I be concerned about it? Can you please do something about it, to fix the problem?
btw, thanks a lot for this library, extremely useful :-)

Mobile devices

This awesome plugin works in any way on mobile devices?

on windows resize event

Ripples not working great when the window is resized. I think reinitialize needed on window resize.

What do you think?

Background-attachment fixed issue

Hi, this is so awesome, and I want to use it in any case, I already spent 4 hours without fixing it.. if I set background-attachment: fixed; the image flickers a lot, it only seems to work in Chrome.. I tried to remove the property position:relative; and set it to position:static; then the mouse over effect doesn't seem to work. Is there any workaround for this ?

thanks

open index.html fail

when I just open index.html,the error is:

Image from origin 'file://' has been blocked from loading by Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null' is therefore not allowed access.

when I run it with a server ,it's ok. I want to know why?

Newbie help

@sirxemic
Awesome effect! I'd like to add it to a touch screen experience in local. I am a newbie and what I did is to copy and paste the html page to Notepad++ and save it as hmtl page. For some reason the water effect doesn't show up and have an error message "TypeError: $(...).ripples is not a function".
Please let me know where I am failing or exact workflow to activate it locally. Thx!

Page Scrolling

When I use it on a page that has the ability to scroll the canvas cuts off at the bottom of the initial height, is there a way to fix this?

Destroy not stopping the rendering or removing the WebGL context

Love this plugin but I have ran into an anomaly.

I know it's not best practice, but bare with me.

AJAX-Page.html

  • Button that uses AJAX to load AJAX-Content.html

AJAX-Content.html

  • Call ripple function on element in THIS page.

Smash the AJAX-Page.html and you're going to get a bunch of instances of the ripple function running on top of each other.

Even if you change AJAX-Content.html to:

AJAX-Content.html

  • Call Destroy ripple on same as below element.
  • Call ripple function on element in this page.

You end up with multiple ripples functions running on the same element.

In other words, Destroy doesn't seem to work when used with AJAX loaded content.

Problem in WordPress version

Hi, this is a nice plugin. I have used it in html version. There is no problem. But, when I trying to integrate in wordpress theme, it showing following errors in console

Uncaught TypeError: (intermediate value)(intermediate value) is not a function

Uncaught TypeError: $(...).ripples is not a function

Please can you help me by fixing this.
Thanks

How do I use this plugin to an irregular lake?

This plugin is great! However, you know, the shapes of many rivers or lakes are irregular. How do I use this plugin to an irregular lake? I find it is only used to create ripples in the rectangular region. I look forward to your reply. Thank you.

ripples doesn't work with background-attachment: fixed

So basically that's the problem. Maybe you can fix this or have a work around this? It seems that it's a bug. It's trying to .getClientBoundRects() from window when it usually gets it from body, the actual thing that's being rippled.

PNG transparency is shown as white

Thank you for developing this great feature. I tried to use PNG as the background image, but it ignores the transparency and is shown as white. I tried to add rgba() and opacity in CSS to get rid of the white, but it still doesn't work. Any idea for solving this problem?

re-initiate after destroy

Love the effect, thanks so much for your stellar work. I know that if I hide the effect, I can use "$('body, main').ripples('show');" to show it again, but how would I start the effect again once it's been destroyed, other than forcing a reload of the page?

Does not work in IE 11

When I run it in IE I get the message "TypeError: Object doesn't support property or method 'ripples'"

adding tags for the repo

Hello @sirxemic ,

I am a member of cdnjs project.
We want to host this library on CDN.
Could you please adding git tags for this repo?

Git tag can help us to know your release version.
And, we could auto-update the lib by a new tag.

Thanks for your help!

cdnjs/cdnjs#8216

Appears differently locally and online

Hello. First of I would like to thank you for your awesome work. I am not a developer but I am in the process of learning. I noticed that the effects seem to be different when viewed locally, compared to the uploaded file.

The scripts I have included are as follows:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> <script src="js/jquery.ripples.js"></script>

I also tried to change the values of dropRadius and perturbance in the jquery.ripples.js file but it doesn't seem to work when I upload the html file to my ftp server. The changes take effect only when viewed locally.

Not even sure what to look for ㅠ.ㅠ

Thanks in advance!

Undefined var

What is may causing this error? your web example works on my browser with jQuery 2.0.0, but with my project it causes the following errors:

Console log with jQuery 3.1.0:

jQuery.Deferred exception: gl is undefined
Ripples.prototype.drop@file:///..../scripts/lib/jquery.ripples.js:566:7
$.fn.ripples/<@file:///..../scripts/lib/jquery.ripples.js:652:9
.each@https://code.jquery.com/jquery-3.1.0.min.js:2:2813
r.prototype.each@https://code.jquery.com/jquery-3.1.0.min.js:2:1001
$.fn.ripples@file:///..../scripts/lib/jquery.ripples.js:640:12
enableRipples@file:///..../scripts/main.js:125:3
@file:///..../scripts/main.js:15:3
g/</j@https://code.jquery.com/jquery-3.1.0.min.js:2:29566
g/</k<@https://code.jquery.com/jquery-3.1.0.min.js:2:29882
undefined
--------------------------------------
  TypeError: gl is undefined     jquery.ripples.js (line 566, col 7)
  gl.viewport(0, 0, this.resolution, this.resolution);

Console log with jQuery 2.0.0:

  TypeError: gl is undefined     jquery.ripples.js (line 566, col 7)
  gl.viewport(0, 0, this.resolution, this.resolution);

Mobile behavior.

Hello.Thank you very much for this cool plugin.
Currently, I added this plug-in on my website and now it works on desktop. However, ripple does not work on mobile.
Do you know the cause?

environment:
ios 11 (iphone SE)

The website is developed using WordPress.
https://endorphins.tokyo

Thank you in advance.

Interactive

Is there a way to use a particular layer to be the receptor for interactions (mouse move and click), but have the effect be on a different layer? I ask because I want the ripples to be behind other objects, but it appears that you have to make the top most div be the one with the effects if you want interactivity.

dropAtMouse mouse position bug

Example:

<div class="rippleWtihBg">
   <div class="divWithContent">
   </div>
</div>

After adding a canvas it does not read mouseover\mouseclick over .divWithContent - ripples show up on an left top corner +- 20px;

Fixed by changing in dropAtMouse function:

e.offsetX || (e.pageX - this.$el.offset().left),
e.offsetY || (e.pageY - this.$el.offset().top),

to:

(e.pageX - this.$el.offset().left) || e.offsetX,
(e.pageY - this.$el.offset().top) || e.offsetY,

Tested on Chrome\Mozilla.

can't use in body with cover style

when body use background picture with url and use style=background-size:cover;
the image disapper, if I give it a width and height and It works.

how to solve this problem.thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.