js中怎么设置span的位置
<divclass="container-fluid"><divclass="container"id="con-rolling"><spanclass="lead"id...
<div class="container-fluid">
<div class="container" id="con-rolling">
<span class="lead" id="rolling">!!!!!!!!!!!</span>
</div>
</div>
我要在js中设置span的位置,比如距离父容器左侧500px的位置,要怎么写,给个思路。谢谢
js文件↓
function Rolling() {
var conWidth = $("#con-rolling").width();
var conWidthNum = parseInt(conWidth);
var conParent = $("#con-rolling").offset().left;
var conParentNum = parseInt(conParent);
var num = 15;
var sum = conWidthNum + conParentNum + 15;
alert(sum);alert(typeof sum);
var rolling = document.getElementById("rolling");
rolling.style.width = sum + "px";
} 展开
<div class="container" id="con-rolling">
<span class="lead" id="rolling">!!!!!!!!!!!</span>
</div>
</div>
我要在js中设置span的位置,比如距离父容器左侧500px的位置,要怎么写,给个思路。谢谢
js文件↓
function Rolling() {
var conWidth = $("#con-rolling").width();
var conWidthNum = parseInt(conWidth);
var conParent = $("#con-rolling").offset().left;
var conParentNum = parseInt(conParent);
var num = 15;
var sum = conWidthNum + conParentNum + 15;
alert(sum);alert(typeof sum);
var rolling = document.getElementById("rolling");
rolling.style.width = sum + "px";
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询