【问题标题】:Button and Slider customizing (Size, Position, Caption size) with Jquery使用 Jquery 自定义按钮和滑块(大小、位置、标题大小)
【发布时间】:2013-11-12 19:39:17
【问题描述】:

我使用 c、php 和 javascript 为我的家庭自动化总线系统构建了一个 web 界面。该功能工作正常,但我无法使用 JQuery 为我的按钮和滑块实现正确的样式。

我想要做的是将按钮和滑块放在“行”中并排在一起,并能够调整它们的大小和样式,以便与常规 PC 浏览器和我的 iOS 设备一起使用。

  1. 按钮大小适用于我的所有设备,但是从 iOS 设备查看时,使用该部分更改按钮字体大小不会影响字体大小。我通过在 html 正文中设置字体大小来帮助自己解决这个问题。这种行为有明显的原因吗?

  2. 谁能给我一个例子,其中有一个与滑块对齐的按钮和一个显示滑块值的数字字段。当然,我已经查看了标准的 Jquery 滑块示例,但是无论我尝试使用类来操纵样式的任何语法组合,我都没有使用我想要的大小、位置(内联)和标签的内联滑块。

以下是我的代码作为参考。 我玩过 Arduinos 和 C++ 中的 Raspberry 编码,但显然我或多或少没有任何 html 或 javascript 经验,所以我非常感谢你的帮助!

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Wipperaller</title>
  <link rel="stylesheet"     href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <style>   
    body{background-color:white;}  
    button{ 
        width: 180px;
        height: 90px;
        font-size: 50px;
        padding-top: 5px;
        padding-bottom: 5px;

        };
    myslider{
        width: 1em;
        height: 1em;
        cursor: default;}

  </style>

  <script>
    function handlerName(busCommand) 
    {
    alert(busCommand.data.msg);
    }

    function SendBusCommand(inputData) {    
    $.ajax({
      type: "POST",
      url: "socketclient_01.php",
      data: inputData.data,
      cache: false,
      success: function(html){
        $("#results").append(html); // hier wird dann der inhalt, 
                                    // den deine datei ausgibt, 
                                    //in das element mit der id results eingetragen
            } 
        });
    }

    $(document).ready(function(){
        $("button").button();
        $("#SZToggle").bind("click", {destination: "11130", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#SZAn").bind("click", {destination: "11130", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#SZAus").bind("click", {destination: "11130", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#SZKabuff").bind("click", {destination: "10206", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#WZToggle").bind("click", {destination: "10106", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#WZWToggle").bind("click", {destination: "10102", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#EZToggle").bind("click", {destination: "11030", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#EZAn").bind("click", {destination: "11030", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#EZAus").bind("click", {destination: "11030", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#EGAus").bind("click", {destination: "32872", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#OGAus").bind("click", {destination: "32882", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#AllesAus").bind("click", {destination: "32868", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#KuToggle").bind("click", {destination: "10104", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#AUELicht").bind("click", {destination: "10403", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#AUTLicht").bind("click", {destination: "10404", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#AUSteck").bind("click", {destination: "10405", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#BADSLicht").bind("click", {destination: "10205", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#BADDLicht").bind("click", {destination: "10302", com: 0x35, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#AlleAuf").bind("click", {destination: "32968", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#AlleZu").bind("click", {destination: "32968", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#EGAuf").bind("click", {destination: "32970", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#EGZu").bind("click", {destination: "32970", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#EGAuf").bind("click", {destination: "32972", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#EGZu").bind("click", {destination: "32972", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#WZJalFrontAuf").bind("click", {destination: "32974", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#WZJalFrontZu").bind("click", {destination: "32974", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
        $("#WZJalSeiteAuf").bind("click", {destination: "32974", com: 0x32, param1: 0x64, param2: 0x00}, SendBusCommand);
        $("#WZJalSeiteZu").bind("click", {destination: "32974", com: 0x32, param1: 0x00, param2: 0x00}, SendBusCommand);
    });
  </script>
</head>

<body>
    <div class="gobalwrapper" style="font-size:24px">
    <h1>Bus Webfrontend</h1>
    <p class="buttons">
            <h2>Licht Gesamt</h2>
            <button id="EGAus">EG Aus</button>
            <button id="OGAus">OG Aus</button>
            <button id="AllesAus">Alles Aus</button>
    </p>
    <p class="buttons">
            <td><h2>Jalousie Gesamt</h2></td>
            <td><button id="AlleZu">Alle Zu</button></td>
            <td><button id="EGZu">EG Zu</button></td>
            <td><button id="OGZu">OG Zu</button></td>
    </p>
    <p class="buttons">
            <td><button id="AlleAuf">Alle Auf</button></td>
            <td><button id="EGAuf">EG Auf</button></td>
            <td><button id="OGAuf">OG Auf</button></td>
    </p>
    <p class="buttons">
            <h2>Licht Wohnzimmer</h2>
            <button id="WZToggle">Fluter</button>
            <button id="WZWToggle">Wand</button>
    </p>
    <p class="buttons">

            <button id="WZJalFrontZu">Front Zu</button>
            <button id="WZJalSeiteZu">Erker Zu</button>
    </p>
    <p class="buttons">         
            <button id="WZJalFrontAuf">Front Auf</button>
            <button id="WZJalSeiteAuf">Erker Auf</button>
    </p>
    <p class="buttons">
            <h2>Esszimmer</h2>
            <button id="EZToggle">Licht</button>
            <button id="EZAn">An</button>
            <button id="EZAus">Aus</button>
    </p>
    <p class="buttons">
            <h2>Küche</h2>
            <button id="KuToggle">Licht</button>
    </p>
    <p class="buttons">
            <h2>Schlafzimmer</h2>
            <button id="SZToggle">Licht</button>
            <button id="SZAn">An</button>
            <button id="SZAus">Aus</button>
            <button id="SZKabuff">Kabuff Aus</button>
            <input type="range" class="myslider" name="slider-1" id="slider-1" value="60" min="0" max="100" />
    </p>
    <p class="buttons">
            <h2>Bad</h2>
            <button id="BADDLicht">Licht</button>
            <button id="BADSLicht">Spiegel</button>
    </p>
    <p class="buttons">
            <h2>Außen</h2>
            <button id="AUELicht">Eingang</button>
            <button id="AUTLicht">Terasse</button>
            <button id="AUSteck">Steckdose</button>
    </p>
    </div>
</body>
</html>

【问题讨论】:

标签: javascript jquery css


【解决方案1】:

按钮大小适用于我的所有设备,但更改 带有该部分的按钮字体大小对 从 iOS 设备查看时的字体大小。我帮助自己解决了这个问题 通过在 html 正文中设置字体大小来解决问题。有没有 这种行为的明显原因?

在调用 .button() 方法后,JQuery UI 通过应用几个 css 类并在里面添加 span 来更改按钮的 html 代码。如果你想改变字体大小 - 你应该写这样的东西:

<style type="text/css">
.ui-button span {
  font-size: 10px;
}
</style>

但更好的方式来改变 ui 元素的外观 - 创建自己的主题或选择一些预制 (http://jqueryui.com/themeroller/)。

有人可以指点我一个有按钮的例子吗 与滑块和显示滑块值的数字字段一致。 当然,我看过标准的 Jquery 滑块示例,但是 我尝试使用类来操作的任何语法组合 造型我从来没有用过尺寸,位置的内联滑块 (内联)和我想要的标签。

使用 display: inline-block;用于按钮和滑块。

【讨论】:

  • 感谢“.ui-button”提示,解决了我的按钮问题。现在我的内联滑块仍然太小了。有没有类似的方法来调整滑块的大小?
  • 试试 .ui-slider { display: inline-block;宽度:300px;您可以在 firefox 中使用 FireBug 扩展来查看元素代码和 css 类。
  • .ui-slider 不起作用,但我还没有安装 FireBug。
  • 使用 FireBug 的调试控制台我发现,
  • 现在我看到“滑块”是指“范围”。这是新的 html 元素,似乎不容易设置样式(谷歌“范围元素样式”)。我建议您改用jqueryui.com/slider。它可自定义并适用于所有浏览器。
猜你喜欢
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多