为什么这不会在车窗的骑行侧创建一个 5 像素宽的垂直条?
<html>
<head runat="server">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#scrollBar").css({
height: $(window).height,
width: 5,
position: "absolute",
top: 0,
left: $(window).width - 5,
margin: 0
});
});
</script>
</head>
<body>
<div id="scrollBar" style="background-color: Red">test
</div>
</body>
</html>
最佳答案
改用这个:
我发现了几个问题:
- 使用
$(window).height() 而不是
$(window).height
, 不要使用
left: $(window).width - 5
,而是使用right: 0
$(document).ready(function() { $("#scrollBar").css({ height: $(window).height(), width: 5, position: "absolute", top: 0, right: 0, margin: 0 }); });
关于jquery - 如何通过JQuery修改div元素的CSS属性(高度宽度)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303600/