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.
加载中,请稍侯......
精彩评论