美化表单——自定义单选按钮和复选按钮

本文提供了一个在线调查表,用于收集用户对于不同电影类型的喜好,并通过投票方式表达了对《Caddyshack》电影的看法。此外,应用了自定义样式为输入框提供了交互式反馈,提升了用户体验。
<form class="form" method="post">    
            <fieldset>
                <legend>Which genres do you like?</legend>
                <input type="checkbox" value="action" id="check-1" name="genre"><label for="check-1" class="">Action / Adventure</label>
                <input type="checkbox" value="comedy" id="check-2" name="genre"><label for="check-2" class="">Comedy</label>
                <input type="checkbox" value="epic" id="check-3" name="genre"><label for="check-3" class="">Epic / Historical</label>
                <input type="checkbox" value="science" id="check-4" name="genre"><label for="check-4" class="">Science Fiction</label>
                <input type="checkbox" value="romance" id="check-5" name="genre"><label for="check-5" class="">Romance</label>
                <input type="checkbox" value="western" id="check-6" name="genre"><label for="check-6" class="">Western</label>
            </fieldset>        
            <fieldset>
                <legend>Caddyshack is the greatest movie of all time, right?</legend>
                <input type="radio" value="1" id="radio-1" name="opinions"><label for="radio-1" class="">Totally</label>
                <input type="radio" value="1" id="radio-2" name="opinions"><label for="radio-2" class="">You must be kidding</label>
                <input type="radio" value="1" id="radio-3" name="opinions"><label for="radio-3" class="">What's Caddyshack?</label>
            </fieldset>
        </form>

<script type="text/javascript">
        jQuery.fn.customInput = function(){
            $(this).each(function(i){
                if($(this).is('[type=checkbox],[type=radio]')){
                    var input = $(this);
                    //get the associated label using the input's id
                    var label = $('label[for='+input.attr('id')+']');
                    //get type,for classname suffix
                    var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
                    //wrap the input + label in a div
                    $('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input,label);
                    //find all inputs in this set using the shared name attribute
                    var allInputs = $('input[name='+input.attr('name')+']');
                    //necessary for browsers that don't support the :hover pseudo class on labels
                    label.hover(function(){
                        $(this).addClass('hover');
                        if(inputType == 'checkbox' && input.is(':checked')) {
                            $(this).addClass('checkedHover');
                        }
                    },function(){
                        $(this).removeClass('hover checkedHover');
                    });
                    
                    //bind custom event, trigger it, bind click,focus,blur events
                    input.bind('updateState',function(){
                        if(input.is(':checked')){
                            if(input.is(':radio')){
                                allInputs.each(function(){
                                    $('label[for='+$(this).attr('id')+']').removeClass('checked');
                                });
                            };
                            label.addClass('checked');
                        } else {
                            label.removeClass('checked checkedHover checkedFocus');
                        }
                    })
                    .trigger('updateState')
                    .click(function(){
                        $(this).trigger('updateState');
                    })
                    .focus(function(){
                        label.addClass('focus');
                        if(inputType == 'checkbox' && input.is(':checked')) {
                            $(this).addClass('checkedFocus');
                        }
                    })
                    .blur(function(){
                        label.removeClass('focus checkedFocus');
                    });                    
                }
            });
        }
    </script>
    <script type="text/javascript">
        $(function(){
            $('input').customInput();
        });
    </script>​
/* CSS for customized radio buttons and check boxes */
            /* page styles */
            body {
                font-size: 62.5%;
            }
            fieldset {
                padding: 0 15px 3em;
                border: 0;
            }
            legend {
                font-size: 1.4em;
                font-weight: bold;
                padding: .2em 5px;
            }
            /* wrapper divs */
            .custom-checkbox, 
            .custom-radio { 
                position: relative; 
            }
            /* input, label positioning */
            .custom-checkbox input,
            .custom-radio input {
                position: absolute;
                left: 2px;
                top: 3px;
                margin: 0;
                z-index: 0;
            }
            .custom-checkbox label,
            .custom-radio label {
                display: block;
                position: relative;
                z-index: 1;
                font-size: 1.3em;
                padding-right: 1em;
                line-height: 1;
                padding: .5em 0 .5em 30px;
                margin: 0 0 .3em;
                cursor: pointer;
            }
            /* states */
            .custom-checkbox label { 
                background: url(http://www.w3cplus.com/sites/default/files/checkbox.gif) no-repeat; 
            }
            .custom-radio label { 
                background: url(http://www.w3cplus.com/sites/default/files/radiobutton.gif) no-repeat; 
            }
            .custom-checkbox label, 
            .custom-radio label {
                background-position: -10px -14px;
            }
            .custom-checkbox label.hover,
            .custom-checkbox label.focus,
            .custom-radio label.hover,
            .custom-radio label.focus {
                background-position: -10px -114px;
            }
            .custom-checkbox label.checked,
            .custom-radio label.checked {
                background-position: -10px -214px;
            }
            .custom-checkbox label.checkedHover,
            .custom-checkbox label.checkedFocus {
                background-position: -10px -314px;
            }
            .custom-checkbox label.focus,
            .custom-radio label.focus {
                outline: 1px dotted #ccc;
            }​

效果图:

效果示例: 点击打开链接
先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱动电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值