www.webdeveloper.com
Results 1 to 4 of 4

Thread: style.filter percentage to hex?

  1. #1
    Join Date
    Dec 2005
    Posts
    492

    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) + ')';
    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?

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    Code:
    function hexpercent(pct){
        var hex= (Math.round(parseFloat(pct)*2.55)).toString(16);
        if(hex.length== 1) hex= '0'+hex;
        return hex;
    }
    hexpercent('100%')

    /* returned value: (String)
    ff
    */

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    var myNum=75;
    
    var myHex= ("0000"+(Math.floor(  (myNum /100)  * 255 )).toString(16)).slice(-2);
    
    alert(myHex)

  4. #4
    Join Date
    Dec 2005
    Posts
    492
    Both work quite nicely. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles