首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调整jqwidget模拟时钟的中心和大小?

如何调整jqwidget模拟时钟的中心和大小?
EN

Stack Overflow用户
提问于 2014-12-04 18:27:10
回答 1查看 718关注 0票数 0

我想根据宽度的百分比值设置时钟的高度和宽度,以填充以下html td (因为时钟需要具有相同的宽度和高度才能成为一个圆)。此外,当我试图使用中心标签时,时钟没有对齐。有谁能推荐一种其他的方法来根据td来调整时钟的尺寸和使时钟中心。

谢谢您的提前,如果我需要解释,如果我太含糊,请告诉我!

以下是来自jqwidget的演示时钟代码的链接:http://jqwidgets.com/jquery-widgets-demo/demos/jqxgauge/index.htm#demos/jqxgauge/gauge-clock.htm

HTML

代码语言:javascript
复制
<td colspan="1" style="width: 26%; height: 250px;";>
  <center>
  <div id="clock" style="position: relative; height:250px;"> 
<div style="position: absolute; left: 0px; top: 0px;" id='seconds'></div>
<div style="position: absolute; left: 0px; top: 0px;" id='hours'></div>
    <div style="position: absolute; left: 0px; top: 0px;" id='minutes'></div>
  </div>
  </center>
</td>

Javascript

代码语言:javascript
复制
  //adding the clock

        var hours = new Date().getHours(),
        minutes = new Date().getMinutes(),
        seconds = new Date().getSeconds(),
        digits = {
            1: 'I',
            2: 'II',
            3: 'III',
            4: 'IV',
            5: 'V',
            6: 'VI',
            7: 'VII',
            8: 'VIII',
            9: 'IX',
            10: 'X',
            11: 'XI',
            12: 'XII'
        };
    $('#minutes').jqxGauge({
        ticksMinor: { visible: false },
        ticksMajor: { visible: false },
        labels: { visible: false },
        animationDuration: 0,
        min: 0, max: 12,
        border: { style: { fill: 'none', stroke: 'none'}, showGradient: false },
        caption: { value: '' },
        colorScheme: 'scheme05',
        style: { fill: 'none', stroke: 'none' },
        pointer: { length: '70%', width: '2%' },
        cap: { style: { fill: '#249dd6', stroke: '#249dd6'} },
        startAngle: -90,
        endAngle: 270,
        value: (minutes / 60) * 12
    });
    $('#hours').jqxGauge({
        ticksMinor: { visible: false },
        ticksMajor: { visible: false },
        labels: { visible: false },
        animationDuration: 0,
        min: 0, max: 12,
        caption: { value: '' },
        border: { style: { fill: 'none', stroke: 'none' }, showGradient: false },
        colorScheme: 'scheme05',
        pointer: { length: '50%', width: '3%' },
        style: { fill: 'none', stroke: 'none' },
        value: hours % 12 + (minutes / 60 * 11) / 12,
        startAngle: -90,
        endAngle: 270
    });
    $('#seconds').jqxGauge({
        ticksMinor: {
            interval: 0.2,
            size: '3%',
            style: {
                fill: '#aaaaaa',
                stroke: '#aaaaaa',
                'stroke-width': '2px'
            }
        },
        ticksMajor: {
            interval: 1,
            size: '8%',
            style: {
                fill: '#aaaaaa',
                stroke: '#aaaaaa',
                'stroke-width': '2px'
            }
        },
        ticksDistance: '10%',
        startAngle: -90,
        endAngle: 270,
        labels: {
            distance: '28%',
            interval: 1,
            formatValue: function (val) {
                if (val == 0) {
                    return '';
                }
                return digits[val];
            }
        },
        pointer: { length: '80%', width: '1.7%' },
        ranges: [],
        caption: { value: 'Time', offset: [0, -30] },
        animationDuration: 0, min: 0, max: 12,
        border: { fill: 'none', stroke: 'none' },
        colorScheme: 'scheme05',
        style: { fill: '#ffffff', stroke: '#cccccc' },
        value: (seconds / 60) * 12
    });
    setInterval(function () {
        var seconds = $('#seconds').jqxGauge('value'),
            minutes = $('#minutes').jqxGauge('value'),
            hours = $('#hours').jqxGauge('value'),
            ratio = 12 / 60;
        seconds += ratio;
        if (seconds > 12) {
            seconds = ratio;
        }
        $('#seconds').jqxGauge('value', seconds);
        if (seconds === ratio) {
            minutes += ratio;
            if (minutes >= 12) {
                minutes = ratio;
            }
            $('#minutes').jqxGauge('value', minutes);
            $('#minutes').jqxGauge('value', minutes);
            hours += 1 / 60;
            if (hours > 12) {
                hours = 1 / 60;
            }
            $('#hours').jqxGauge('value', hours);
        }
    }, 1000);





  //end of clock code
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-04 18:34:09

<center>标记基本上被忽略,因为#clock div将占用td的整个宽度。

试着..。移除<center></center>并放置..。

代码语言:javascript
复制
text-align:center;

..。进入#时钟div的样式。

我不能说这会起作用,因为我无法使用在页面上运行的jqxGauge来访问它。

更新

jqxGauge有宽度和高度的选项.

代码语言:javascript
复制
$('#gauge').jqxGauge({ width: '20%', height: '30%', radius: '50%' });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27301274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档