正如标题所示,我正在做我的第一个响应式设计网站..我有一个图像滑块div设置使用像素和媒体查询。我希望能够访问宽度,以便我可以告诉图像滑块我需要移动多远。不幸的是,媒体查询似乎没有改变HTML。是否有任何解决方法来获取该信息,以便我可以在JavaScript中使用它。css响应式设计具有dificulty访问宽度与javascript
这里是一个简单的网页例子玩和的jsfiddle http://jsfiddle.net/synthet1c/sNbW9/
感谢您的帮助
body{
position:absolute;
background:red;
width:100%;
height:100%;
}
#outer{
position:absolute;
width:80%;
height:80%;
background:red;
background-image:url('http://www.largepictures.net/largepictures/scenery/largepictures_scenery_large_3066.jpg');
background-position: center;
margin:auto;
}
#inner{
width:80%;
height:80%;
background:rgba(255,0,0,0.3)
margin:auto;
margin-top:5%;
}
<script>
document.getElementById('inner').onclick = function(){
alert(document.getElementById('inner').style.width);
}
</script>
<div id="outer">
<div id="inner">click the box to get width</div>
</div>
非常感谢大卫,完美的作品! – synthet1c 2013-05-10 19:06:56
非常欢迎,我很乐意帮助! =) – 2013-05-10 19:08:58