/    Sign up×
Community /Pin to ProfileBookmark

style.filter percentage to hex?

I’m working with a style.filter related function.

Some of my function appear as …

[CODE]document.getElementById(‘audio’).style.filter = ‘progid:DXImageTransform.Microsoft.gradient(startColorstr=#A8’ + c.substring(1) + ‘,endColorstr=#A8’ + c.substring(1) + ‘)’;[/CODE]

Everything is working but I’m trying to replace the “A8” part with a percentage typed in by the viewer.

The percentage is simply a non-decimal number between 0 and 100 typed into a box.

I know how to grab the value of the box (again, it’s 0-100) but how do I convert that number into it’s “A8” equivalent?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMay 27.2011 — [CODE]function hexpercent(pct){
var hex= (Math.round(parseFloat(pct)*2.55)).toString(16);
if(hex.length== 1) hex= '0'+hex;
return hex;
}[/CODE]


hexpercent('100%')

/* returned value: (String)

ff

*
/
Copy linkTweet thisAlerts:
@rnd_meMay 27.2011 — [CODE]var myNum=75;

var myHex= ("0000"+(Math.floor( (myNum /100) * 255 )).toString(16)).slice(-2);

alert(myHex)[/CODE]
Copy linkTweet thisAlerts:
@robindeanauthorMay 27.2011 — Both work quite nicely. Thanks!
×

Success!

Help @robindean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...