<script src="https://raw.githubusercontent.com/jquery/jquery-color/master/jquery.color.js"></script>
<input type="button" value="again!"><br>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
<span class="messageanimate message">
notice me!
</span>
Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia.
<div class="messageanimate message block">
notice me!
</div>
Nam pretium...
CSS
.block {
padding:10px;
margin:10px;
border:1px solid #880;
border-radius:5px;
background:#ffd;
}
.message {
color:#f26522;
}
.messageanimate {}
/*
NB: this could probably also be done using css transitions and adding and removing a class with some delay?
*/
JavaScript
$(document).ready(function(){
messageanimate();
$('input[type=button]').click(messageanimate);
});
function messageanimate(){
$('.messageanimate').each(function(){
var $target = $(this), newstyle = {}, oldstyle = {}, resetstyle = {}, options = {};
// NB to animate colors, the jQuery-color plugin is needed:
// https://github.com/jquery/jquery-color
newstyle = {
'color':'#f00',
'borderWidth':'1px',
'borderColor':'#f00',
'backgroundColor':'#ffdddd'
// 'textIndent':'10px'
};
$.each(newstyle, function(prop,val){
resetstyle[prop] = '';
oldstyle[prop] = '';
try{
oldstyle[prop] = $target.css(prop);
}catch(e){
console.log('cannot read .css(prop):' + prop);
try{
oldstyle[prop] = $target.get(0).style[prop];
}catch(e){
console.log('cannot read .style[prop]:' + prop);
}
}
});
console.log(newstyle,oldstyle,resetstyle,options);
options.complete = function (){
$(this).css(resetstyle);
}
$target
// .css(newstyle)
.delay(500)
.animate(newstyle,200)
.animate(oldstyle,200)
.animate(newstyle,200)
.animate(oldstyle, options)
;
});
}
////////////////////
// including this file does not work so I have to copy-paste its contents below.
// source : https://raw.githubusercontent.com/jquery/jquery-color/master/jquery.color.js
// Error:
// Refused to execute script from
// 'https://raw.githubusercontent.com/jquery/jquery-color/master/jquery.color.js'
// because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
////////////////////
/*!
* jQuery Color Animations v@VERSION
* https://github.com/jquery/jquery-color
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* Date: @DATE
*/
(function( jQuery, undefined ) {
var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.