开发者

Setting element width() does not work with a variable

I'm trying to set an element width using jQuery and it just won't work.

Here is my code:

var $padding = 30,
$oddWidth = parseInt( Math.round( $(window).width()*0开发者_开发问答.75 ) ),
$odd = $oddWidth-$padding;

$('div:jqmData(role="content")').css({ 'margin-left':'25%'}).width( $odd );

Can anybody help me out?


The following is working for me, so are you wrapping the jQuery code inside the following?

$(document).ready(function() {
    $("div:jqmData(role='page')").live('pageshow',function(){
        var $padding = 30,
        $oddWidth = parseInt( Math.round( $(window).width()*0.75 ) ),
        $odd = $oddWidth-$padding;
        $('div:jqmData(role="content")').css({ 'margin-left':'25%'}).width( $odd );
    });
});

jQuery.mobile has a different document.ready() for when a "page" is fully loaded, so perhaps without this, the width() is not correct or the <div data-role="content"> does not exist yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜