javascript如何使里程表在调整窗口大小时更改其宽度
如何使div id=“odometerDiv”在调整窗口大小时更改其宽度,以便:javascript如何使里程表在调整窗口大小时更改其宽度,javascript,jquery,window-resize,Javascript,Jquery,Window Resize,如何使div id=“odometerDiv”在调整窗口大小时更改其宽度,以便: 在600px宽度以上有更大的宽度断点和 600px以下是否有较小的宽度断点 我已经尝试过CSS,在应用CSS div id=“odometerDiv”后停止。它必须在javascript代码中完成。我是javascirpt初学者,请帮助:) 以下是我的答覆: 功能里程表(parentDiv,opts){ 若(!parentDiv)抛出“错误:里程表对象必须超过文档元素。”; 这个数字=6; 这十分之一=0; 这
功能里程表(parentDiv,opts){
若(!parentDiv)抛出“错误:里程表对象必须超过文档元素。”;
这个数字=6;
这十分之一=0;
这个数字=40;
this.digitPadding=0;
这个.digitWidth=30;
这是1.bustness=2;
this.fontStyle=“font系列:Courier New,Courier,monospace;字体重量:900;”;
这个值=-1;
for(var key in opts){this[key]=opts[key];}
变量样式={
数字:“位置:绝对;高度:“+this.digithweight+”px;宽度:“+(this.digitWidth-(2*this.digitPadding))+”px+
“padding:“+this.digitPadding+”px;字体大小:”+(this.digithweight-(2*this.digitPadding))+”px+
“背景:黑色;颜色:白色;文本对齐:居中;”+this.fontStyle,
列:“位置:相对;浮动:左侧;溢出:隐藏+
高度:“+this.digithweight+”px;宽度:“+this.digithwidth+”px;”,
突出显示:“位置:绝对;背景:白色;不透明度:0.25;过滤器:alpha(不透明度=25);宽度:100%;左侧:0px;”,
低光:“位置:绝对;背景:黑色;不透明度:0.25;过滤器:alpha(不透明度=25);宽度:100%;左侧:0px;”,
侧面突出显示:“位置:绝对;背景:白色;不透明度:0.50;过滤器:alpha(不透明度=50);高度:100%;顶部:0px;”,
sidelowlight:“位置:绝对;背景:黑色;不透明度:0.50;过滤器:alpha(不透明度=50);高度:100%;顶部:0px;”
};
变量突出显示=[
“顶部:20%;高度:32%;”+style.highlight,
“顶部:27.5%;高度:16%;”+style.highlight,
“顶部:32.5%;高度:6%;”+style.highlight,
“右侧:0%;宽度:6%;”+style.sidelowlight,
“左:0%;宽:4%;”+style.sidehighlight,
“顶部:0%;高度:14%;”+style.lowlight,
“底部:0%;高度:25%;”+style.lowlight,
“底部:0%;高度:8%;”+style.lowlight
];
this.setDigitValue=函数(数字、数值、分形){
var di=数字信息[数字];
var px=数学地板(此数字高度*分形);
px=px+di.offset;
如果(val!=di.last\u val){
var tmp=di.digitA;
di.digitA=di.digib;
di.digib=tmp;
di.digitA.innerHTML=val;
di.digib.innerHTML=(1+Number(val))%10;
di.last_val=val;
}
如果(px!=di.last_px){
di.digitA.style.top=(0-px)+“px”;
di.digib.style.top=(0-px+this.digithweight)+“px”;
di.last_px=px;
}
};
this.set=函数(无效){
若(无效<0)抛出“错误:里程表值不能为负。”;
该值=无效;
如果(十分之一)无效=无效*10;
变量numb=数学楼层(无效);
var frac=无效-无效;
numb=字符串(numb);
对于(变量i=0;i”;//用于哑IE
hdiv.style.cssText=高光[j];
数字分频器(hdiv);
}
odometerDiv.appendChild(数字科尔迪夫);
var offset=Math.floor(Math.random()*this.bustness);
push({digitA:digitDivA,digib:digitDivB,last_val:-1,last_px:-1,offset:offset});
};
如果(十分之一){
digitInfo[this.digits-1].digitA.style.background=“红色”;
digitInfo[this.digits-1].digitB.style.background=“红色”;
digitInfo[this.digits-1].digitA.style.color=“#000000”;
digitInfo[this.digits-1].digib.style.color=“#000000”;
}
如果(this.value>=0)此.set(this.value);
}
//这是启动里程表的函数,但它不起作用,我是javascript初学者,请帮助:)
//
开始计算();
$(“按钮”)。单击(函数(){
var currentvalue=myOdometer.get();
$('#value')。文本(currentvalue);
});代码>
#里程计rdiv{
高度:60px;
}
#价值观{
宽度:400px;
高度:40px;
利润率:20px0;
文本对齐:居中;
线高:40px;
字体大小:20px;
背景:橙色;
}
钮扣{
宽度:100px;
高度:20px;
}
只需在css中使用媒体查询:
#odometerDiv {
// Styles for when the screen is wider than or equal to 600px
}
@media (max-width: 600px) {
#odometerDiv {
// Styles for when the screen is less than 600px
}
}
只需在css中使用媒体查询:
#odometerDiv {
// Styles for when the screen is wider than or equal to 600px
}
@media (max-width: 600px) {
#odometerDiv {
// Styles for when the screen is less than 600px
}
}
你确定你需要用JS来做吗?我认为这可以通过CSS和媒体查询来完成……你确定需要用JS来完成吗?我认为它可以通过CSS和媒体查询来完成。。。