Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Color Compare Range Slider

Posted on Jun 13 For this week's Codepen Challenge, I did a Color Compare Range Slider. It's using an to switch between two selectable colors of your own choice.A Codepen-user asked this:How did you do this?It's not super complex, but requires a lot of visuals to explain, so let's dive in!First, you need an image where all the pixels you do not want to color, are transparent:The same image will be used twice: Once as a regular image in an -tag, and as a custom property: --cc-mask:url(path-to-image).Then you style an :The background is a linear-gradient with a hard stop-point behind the thumb (the grey bar):--_c1 and --_c2 are the colors. These are updated from javaScript, when you select a different color. The --_x is the current value of the range-sldier.Then you add the image as a mask and set mix-blend-mode to multiply:You then add the behind the range-slider, and we're almost there:Finally, we'll add two .I'm using two small helper-scripts, one for setting the scope of a CSS Custom Property and one for setting the property (see the code in the Codepen below).On the wrapper,

, we add an eventListener, that'll update the three CSS Custom Properties we're using:And that's it — hope it makes sense!Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Ha Anna - May 12 Maxime - Jun 3 Santhosh (sandy inspires) - May 21 Pragati Verma - Jun 6 Once suspended, madsstoumann will not be able to comment or publish posts until their suspension is removed. Once unsuspended, madsstoumann will be able to comment and publish posts again. Once unpublished, all posts by madsstoumann will become hidden and only accessible to themselves. If madsstoumann is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Mads Stoumann. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag madsstoumann: madsstoumann consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging madsstoumann will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.


This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Color Compare Range Slider

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×