2

我的 jquery 有什么问题?我想根据屏幕大小使我的 div 更大,并且有很多很好的例子,但仍然没有成功。

.picLeft {
    border: 4px solid black;
    border-radius: 15px;
    width: 130px !important;-------> I need to change this
    height: 130px;-------> I need to change this
    text-align: center;
    background-color: white;
    margin: 10px !important;
    padding: 0px;
    float: left;
}

**EDIT TWO DIVS LIKE THAT**
var height = window.innerHeight;
var width = window.innerWidth;
console.log("height------->" +height);
console.log("width-------->" +width);
// <div class="ui-block-a picLeft" id="leftDiv">
//$("#leftDiv").css("width","300 !important"); NOT working
$(".picLeft").css("width","300 !important"); //NOT Working

<div class="ui-grid-a"   style="background-color:black">
    <div class="ui-block-a picLeft" id="leftDiv">
    <img src="images/nk100x100.jpg" data-theme="c"
                id="pictureId" />
</div>
    <div class="ui-block-b picRight">
        <img src="images/th100x100.jpg" data-theme="c" id="pictureId2"  />
    </div>
</div>

谢谢!萨米人

4

5 回答 5

2

这个怎么样:

$(window).resize(function()
{
    $('#display').css('width', ($(this).width() - 100) + 'px');
});​

http://jsfiddle.net/qJCc9/

于 2012-07-23T12:14:54.863 回答
2
$(".picLeft").css("width","300px !important"); //Added "px"
于 2012-07-23T12:12:47.923 回答
2

你错过了px

$(".picLeft").css("width","300px !important"); 

我建议使用百分比值或 CSS3 媒体查询来执行此操作。

于 2012-07-23T12:13:05.303 回答
1

You can use an expression in your css file something like the example below too:

width: expression((document.body.clientWidth - 300)  + "px") !important;

Thought it might be useful. You can also do conditional ones like this too:

width: expression( document.body.clientWidth > 1000 ? "1000px" : "99%" ); 

I know this isn't what you asked but others have already given good examples; this is just an alternative.

于 2012-07-23T12:16:35.050 回答
1

尝试这个...

 var width = jQuery(window).width();       
 jQuery('div.picLeft').css('width':width); 
 jQuery(window).resize(function() {
        var width = jQuery(window).width();  
        jQuery('div.picLeft').css('width':width);
    });
于 2012-07-23T12:14:30.000 回答