Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Move this topic
Forum :
Getting Started
Using jQuery
Using jQuery Plugins
Using jQuery UI
Developing jQuery Core
Developing jQuery Plugins
Developing jQuery UI
QUnit and Testing
About the jQuery Forum
jQuery Conferences
jQuery Mobile
Developing jQuery Mobile
Sub forum :
Move this topic
Cancel
Using jQuery Plugins
mikeebee8
Using jQuery Color to cycle through some specified colours
in
Using jQuery Plugins
•
10 years ago
Hi all,
I followed a
tutorial
which explained how to use the jQuery color plugin to cycle through random colours.
spectrum();
function spectrum(){
var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
$('#container').animate( { backgroundColor: hue }, 1000);
spectrum();
}
This works great but I'd like to
limit it to X number of specific colours
. Is this an easy change? I tried altering it myself but got nowhere fast.
Cheers
1
Replies(4)
jakecigar
Re: Using jQuery Color to cycle through some specified colours
10 years ago
Your code is not a "plugin". It’s just a one field only function. This code is a plugin
$.fn.spectrum=function(arrayOfColors){
return this.each(function(){
var self=$(this);
(function spectrum(){
var hue=arrayOfColors.shift()
arrayOfColors.push(hue)
self.animate({ backgroundColor: hue }, 1000,spectrum)
})();
})
}
And this is how you might use it.
function randomHues(n){
var res=[]
for(var i=0;i<n;i++)
res.push('rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')')
return res
}
var hues=randomHues(10) // or hardcode your own
$(function(){
$('#container').spectrum(hues);
})
I tested it with off the shelf jquery-ui-1.8.16, and not "the color plugin", but it should be the same.
JΛ̊KE
Leave a comment on jakecigar's reply
mikeebee8
Re: Using jQuery Color to cycle through some specified colours
10 years ago
Ah apologies, I posted in this forum as I thought 'Color' was a plugin.
That works great, I see that you've added
// or hardcode your own
could you explain how to add specific colours (rgb values) please?
Many thanks
jakecigar
Re: Re: Using jQuery Color to cycle through some specified colours
10 years ago
You can use any number of silly / disgusting / revolting / annoying colors.
var hues=["red","blue","yellow"]
var hues=["rgb(110,220,130)","rgb(230,220,210)","rgb(140,110,150)"]
Use subtle colors!
JΛ̊KE
Leave a comment on mikeebee8's reply
mikeebee8
Re: Using jQuery Color to cycle through some specified colours
10 years ago
Ooo thanks I'm gonna light the page up like a f'in Christmas tree woo hoo!
Many thanks Jake!
Leave a comment on mikeebee8's reply
Change topic type
Topic Type :
Discussions
Questions
Ideas
Problems
No of days :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to mikeebee8's question
Top
Reply
{"z2972146":[14737000002894503,14737000002894788,14737000002904308],"z2950240":[14737000002898318,14737000002899351]}
Statistics
4
Replies
6266
Views
1
Followers
Tags
Cancel
color
Actions
Permalink
Related Posts
Animate color
Color choosing
change color
change color
button color
hover color