<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
<meta charset=utf-8 />
<title>Pulsate</title>
<style>
div { clear: left; margin-bottom: 2em; }
.pulsating-block {
width: 6em; height: 4em;
margin: 0.5em; margin-right: 10em;
float: left; clear: none; position: relative;
background: lightblue;
text-align: center;
padding-top: 2em;
font: bold 1em sans-serif;
}
</style>
</head>
<body>
<div>
<div class="Linear opacity pulsating-block">linear</div>
</div>
</body>
</html>
(function ($) {
$.fn.pulsate = function (properties, duration, type, speed, callback) {
type = type || 'Swing'
speed = speed || 'Normal';
this.animate(properties, duration, 'pulsate' + type + speed, callback);
};
function createPulsateLinear (speed) {
speed *= 2;
return function (p, n) {
return (Math.asin(Math.sin(Math.PI * n / speed)) + Math.PI / 2) / Math.PI;
}
}
function createPulsateSwing (speed) {
return function (p, n) {
return (1 + Math.sin(n / speed)) / 2;
}
}
function createPulsateBounce (speed) {
speed *= 2;
return function (p, n) {
return (
((Math.asin(Math.sin(Math.PI * n / speed)) + Math.PI / 2) / Math.PI) *
(Math.sin(Math.PI * n / speed) + 1) / -2 + 1
);
}
}
var speeds = {
fast: 100,
normal: 200,
slow: 1000
}
$.extend(jQuery.easing, {
pulsateLinearFast: createPulsateLinear(speeds.fast),
pulsateLinearNormal: createPulsateLinear(speeds.normal),
pulsateLinearSlow: createPulsateLinear(speeds.slow),
pulsateSwingFast: createPulsateSwing(speeds.fast),
pulsateSwingNormal: createPulsateSwing(speeds.normal),
pulsateSwingSlow: createPulsateSwing(speeds.slow),
pulsateBounceFast: createPulsateBounce(speeds.fast),
pulsateBounceNormal: createPulsateBounce(speeds.normal),
pulsateBounceSlow: createPulsateBounce(speeds.slow)
});
})(jQuery);
$(document).ready(function() {
var
pulsatingBlocks = $('.pulsating-block'),
forever = 5 * 24 * 60 * 60 * 1000; // 5 days! (Which is forever in Internet time)
pulsatingBlocks.filter('.opacity').each(function () {
$(this).pulsate({left: "+=500"}, forever, this.className.split(' ')[0], 'Slow');
});
pulsatingBlocks.filter('.top').each(function () {
$(this).pulsate({top: 100}, forever, this.className.split(' ')[0], 'Fast');
});
});
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |