开源软件名称(OpenSource Name):matthias-vogt/legitRipple.js开源软件地址(OpenSource Url):https://github.com/matthias-vogt/legitRipple.js开源编程语言(OpenSource Language):CSS 48.0%开源软件介绍(OpenSource Introduction):legitRipple.jsA jQuery plugin for legit Material-Design ripple effects.
UsagelegitRipple.js depends on jQuery, so make sure you have that loaded. When the DOM is ready, you can use it like this: //ripple with default options
$(".some, .elements").ripple(); //ripple with custom options
$(".elements").ripple({
scaleMode: false,
maxDiameter: "100%"
}); You can also use alternative syntax if you have a lot of ripple elements with different options. $.ripple({
".material": {},
".material.circle": {maxDiameter: "100%"},
".customHTML": {template: $("<p/>").text("Custom ripple content!")},
".callback": {
callback: function($container, $ripple, posI, maxDiameter) {
//is called whenever the ripple's css properties change
}
}
}); You can't apply the ripple effect on Install<link href="stylesheet" type="text/css" href="ripple.min.css">
<script src="jquery.min.js"></script>
<script src="ripple.min.js"></script> For better loading performance, I'd recommend loading the script as non-critical content (by putting the Install and update easily using bower: bower install --save legitripple Options
Coming soon
Destroying, unbinding and overwritingRipples can be overwritten as you'd expect: $(".ripple").ripple();
$(".ripple.noScale").ripple({scaleMode: 0});
//.ripple has default options
//.ripple.noScale has default options and {scaleMode: 0}
$(".ripple.noScale").ripple({scaleMode: 0});
$(".ripple").ripple();
//.ripple and ripple.noScale have default options You can also unbind event handlers from ripples or destroy all ripples. $(".ripple").ripple({unbind: true});
//removes all event handlers from a ripple element.
//if you call it during a ripple animation, the animation
//will still complete
$.ripple.destroy();
//stops any ripple animations in their tracks and removes any
//plugin created elements, classes and event bindings.
//calling .ripple() will still work Custom ripplesCustom CSSRipples can be targeted using the .container .legitRipple-ripple {
background: yellow;
/* You can change the transition properties too!
Just don't try and change the width transition's easing. */
transition-duration: .15s, .9s; /*width, opacity*/
} Custom elementsYou can even use custom elements for ripples by setting the Alternatively, you can set the <div>
Container Element
<div class="legitRipple-template">Your custom element</div>
</div> How the code will look when a ripple is triggered: <div class="legitRipple">
Container Element
<div class="legitRipple-template">Your custom element</div>
<span class="legitRipple-ripple legitRipple-custom">
<div>Your custom element</div>
</span>
</div> The custom element is used as a template and will be hidden by CSS on load. When a ripple is triggered, the custom element will be By default, when using custom ripple elements, each direct child of .legitRipple-custom > * {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
transform: translate(-50%, -50%);
} Manually controlling ripplesSince ripple elements will only be removed on $(".ripple-element>.legitRipple-ripple").css("opacity", "0 !important"); Moreover, you can manually trigger ripples like in the demo by faking mousedown/touchstart events and do some crazy stuff with it. CallbackFor the callback option, you can pass a function which is called everytime the ripple's style attribute changes. $(".elements").ripple({callback: function($container, $ripple, posI, maxDiameter) {
/* $container: The ripple container element
$ripple: The ripple element
posI: An array with two indices (0 <= i <= 1) for the
x- and y-position of the ripple relative to the parent
maxDiameter: A string with the max-width of the ripple
element with unit ("120%", "10em", …)
*/
}}); Touch supportlegitRipple.js has full touch support. You can even use multi-touch for multiple ripples in different elements at the same time. MotivationOn Android, ripples don't spread in all directions equally as fast. They're positioned relative to the touch position as the touch position is positioned relative to the ripple's container.
There are a lot of similar plugins out there but this effect, hadn't been replicated in any of them AFAIK (which is not surprising since it's not documented in Google's Material Design spec either), so I decided to make my own. Update: I did some more research and this effect can be achieved with the paper-ripple Polymer element, using the recenters attribute which makes ripples "grow toward the center of [their] container". So definitely use that if you use polymer. Adding to the incentive was that the plugins I saw don't slow the ripple spread on mousedown and speed it up again on mouseup or don't have dragging or touch support implemented correctly. legitRipple.js is probably also the only one which works with inline elements and has ripples with customizable HTML. Maybe it's a bit overkill for this simple effect but that's your call to decide ;) Browser supportThis uses CSS3 transitions, so browser support is ie10+. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论