connectseekers.com

Friday, 3 July 2015

Slider Colorpicker Horizontal Direction Using jQuery in Asp.Net

7/03/2015 - By Pranav Singh 0

This article will show you how you can create a Slider Colorpicker Horizontal Direction Using jQuery in Asp.Net. In this I will show you how to make a color with different color combination red, blue and green.


<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

Now check the below jquery code and add into the page.  This code will display and make the color combination. As we move the red, blue and green color into the square box. Now here is the code.

<script language="javascript">
        function ColorManager(rcolor, gcolor, bcolor) {
            var hex = [
                          r.toString(16),
                          g.toString(16),
                          b.toString(16)
                      ];
            $.each(hex, function (nr, val) {
                if (val.length === 1) {
                    hex[nr] = "0" + val;
                }
            });
            return hex.join("").toUpperCase();
        }
        function refreshSwatch() {
            var red = $("#redslider").slider("value"),
      green = $("#greenslider").slider("value"),
      blue = $("#blueslider").slider("value"),
      hex = ColorManager(redcolor, greencolor, bluecolor);
            $("#colorcombination").css("background-color", "#" + hex);
        }
        $(function () {
            $("#redslider, #greenslider, #blueslider").slider({
                orientation: "horizontal",
                range: "min",
                max: 255,
                value: 127,
                slide: refreshSwatch,
                change: refreshSwatch
            });
            $("#redslider").slider("value", 120);
            $("#greenslider").slider("value", 60);
            $("#blueslider").slider("value", 100);
        });
    </script>

In above code we have selector function by passing the value into ColorManager function. Now here is the complete code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm14.aspx.cs" Inherits="WebApplication2.WebForm14" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Slider Colorpicker Horizontal Direction Using jQuery in Asp.Net</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <style>
        #redslider, #greenslider, #blueslider
        {
            float: left;
            clear: left;
            width: 300px;
            margin: 15px;
        }
        #colorcombination
        {
            width: 100px;
            height: 80px;
            margin-top: 18px;
            margin-left: 350px;
            background-image: none;
        }
        #redslider .ui-slider-range
        {
            background: #ef2929;
        }
        #redslider .ui-slider-handle
        {
            border-color: #ef2929;
        }
        #greenslider .ui-slider-range
        {
            background: #8ae234;
        }
        #greenslider .ui-slider-handle
        {
            border-color: #8ae234;
        }
        #blueslider .ui-slider-range
        {
            background: #729fcf;
        }
        #blueslider .ui-slider-handle
        {
            border-color: #729fcf;
        }
    </style>
    <script language="javascript">
        function ColorManager(rcolor, gcolor, bcolor) {
            var hex = [
                          r.toString(16),
                          g.toString(16),
                          b.toString(16)
                      ];
            $.each(hex, function (nr, val) {
                if (val.length === 1) {
                    hex[nr] = "0" + val;
                }
            });
            return hex.join("").toUpperCase();
        }
        function refreshSwatch() {
            var red = $("#redslider").slider("value"),
      green = $("#greenslider").slider("value"),
      blue = $("#blueslider").slider("value"),
      hex = ColorManager(redcolor, greencolor, bluecolor);
            $("#colorcombination").css("background-color", "#" + hex);
        }
        $(function () {
            $("#redslider, #greenslider, #blueslider").slider({
                orientation: "horizontal",
                range: "min",
                max: 255,
                value: 127,
                slide: refreshSwatch,
                change: refreshSwatch
            });
            $("#redslider").slider("value", 120);
            $("#greenslider").slider("value", 60);
            $("#blueslider").slider("value", 100);
        });
    </script>
</head>
<body class="ui-widget-content" style="border: 0;">
    <form id="form1" runat="server">
    <div id="redslider">
    </div>
    <div id="greenslider">
    </div>
    <div id="blueslider">
    </div>
    <div id="colorcombination" class="ui-widget-content ui-corner-all">
    </div>
    </form>
</body>
</html>

Now we have done run the application to check the output.


DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top