动态更改按钮jquerymobile中文本的大小

时间:2012-06-19 18:38:45

标签: button text jquery-mobile

我有以下代码生成jquerymobile样式按钮

<a href="#" data-role="button"  
        data-theme="b" id="svbutton" style="position: absolute; top: 30%; margin-left: 0%;margin-right: 0%;  width: 80%; height: 20%; text-align: center;  font-size: 2.50em">Load Time...</a>

确实,当屏幕重新缩放时,按钮的大小会发生变化。但是文本的大小不会改变。有没有办法根据设备屏幕的大小来改变大小?

2 个答案:

答案 0 :(得分:1)

您可以阅读文档的宽度或按钮,然后使按钮的字体大小相对于该宽度,例如:

var buttonWidth = $('#svbutton').width();
var fontSize = buttonWidth / 10;
$('#svbutton').css('font-size', fontSize + 'px');

<强>的jsfiddle
http://jsfiddle.net/VFube/1

答案 1 :(得分:0)

直播示例:

JS:

// For all buttons use something like this
$('.ui-btn').css('width','50%');

// For individual buttons use something like this
$('#theButton1').parent().css('width', '75%');

// Or this for HREF data-role buttons
$('#hrefButton4').css('width', '45%');

我认为这就是你要找的东西

// this changes the height for all buttons
$('.ui-btn-text').css('font-size','50px');

// This changes the height for a single element 
$('#hrefButton3').children().children().css('font-size','30px');

HTML:

<div data-role="page" id="home"> 
    <div data-role="content">
        <input type="button" id="theButton1" value="Press Me 1" />
        <input type="button" id="theButton2" value="Press Me 2" />
        <input type="button" id="theButton3" value="Press Me 3" />
        <input type="button" id="theButton4" value="Press Me 4" />
        <br />
        <a href="#" data-role="button" id="hrefButton1">HREF Me 1</a>
        <a href="#" data-role="button" id="hrefButton2">HREF Me 2</a>
        <a href="#" data-role="button" id="hrefButton3">HREF Me 3</a>
        <a href="#" data-role="button" id="hrefButton4">HREF Me 4</a>
    </div>
</div>

相关:

相关问题