请在这里看到我的代码
http://jsbin.com/ijoxa3/edit
var drawHorizondalLine = function(x1,y1,x2,y2, color) {
var width = Math.abs(x1 - x2);
var posX = (x1 > x2) ? x1 : x2;
var id ='c_'+new Date().getTime()
var line = "<div id='"+id+"'class='line'> </div>";
$('body').append(line);
$('#'+id).css({
left: posX,
top: y1,
width: width,
position:'absolute',
backgroundColor: color
});
};
$(document).ready(function() {
drawHorizondalLine(0, 10, 200, 10, '#a00');
drawHorizondalLine(0, 50, 100, 50, '#0a0');
});
<style>
.line{
padding;1px;
}
</style>
<body>
<p id="hello">Hello World</p>
</body>
</html>â
函数调用
drawHorizondalLine(0, 10, 200, 10, '#a00');
假设从页面左上角画一条线,长度为100px,但该线似乎从正文的最后一个分区开始。
错误在哪里?