需要帮助定位基于it的元素';s宽度(Javascript)
我正在开发一个stepper用户界面,而且“前进”的东西似乎工作得很好。从“第3步”之后向后看,定位似乎已关闭。我想我瞄准了错误的元素,但我不确定 感谢您的帮助。代码笔: HTML需要帮助定位基于it的元素';s宽度(Javascript),javascript,html,Javascript,Html,我正在开发一个stepper用户界面,而且“前进”的东西似乎工作得很好。从“第3步”之后向后看,定位似乎已关闭。我想我瞄准了错误的元素,但我不确定 感谢您的帮助。代码笔: HTML 您需要在translate属性上保留减号 function regress(){ // Look for the active step let activeStep = document.querySelector('.active'); // Look for the previous step
您需要在
translate
属性上保留减号
function regress(){
// Look for the active step
let activeStep = document.querySelector('.active');
// Look for the previous step
let previousStep = activeStep.previousSibling;
// Get the width of the element
stepWidth = stepWidth - previousStep.clientWidth - 32;
// Step backwards
stepPlace--;
// Count the steps
let stepCount = document.getElementsByClassName('step').length;
// Calculate the new width of the meter
meterWidth = ((100/stepCount)*stepPlace);
// Update the styling to show the new meter width
progressMeter.style.cssText = "width:"+meterWidth+"%;"
// Slide the text to the left using the width of the step element
steps.style.cssText = "transform:translateX(-"+(stepWidth)+"px);" // <-- here
// Remove the .active class from the active step
activeStep.classList.remove('active');
// Add the .active class to the newly active step
previousStep.classList.add('active');
console.log(stepWidth);
};
函数回归(){
//查找活动步骤
让activeStep=document.querySelector('.active');
//查找上一步
让previousStep=activeStep.previousSibling;
//获取元素的宽度
stepWidth=stepWidth-previousStep.clientWidth-32;
//退后一步
台阶--;
//数台阶
让stepCount=document.getElementsByClassName('step').length;
//计算米的新宽度
米宽=((100/步数)*步位);
//更新样式以显示新的米宽
progressMeter.style.cssText=“宽度:+meterWidth+”%;”
//使用step元素的宽度向左滑动文本
steps.style.cssText=“transform:translateX(-“+(步长)+”px);”//成功了!谢谢。
function regress(){
// Look for the active step
let activeStep = document.querySelector('.active');
// Look for the previous step
let previousStep = activeStep.previousSibling;
// Get the width of the element
stepWidth = stepWidth - previousStep.clientWidth - 32;
// Step backwards
stepPlace--;
// Count the steps
let stepCount = document.getElementsByClassName('step').length;
// Calculate the new width of the meter
meterWidth = ((100/stepCount)*stepPlace);
// Update the styling to show the new meter width
progressMeter.style.cssText = "width:"+meterWidth+"%;"
// Slide the text to the left using the width of the step element
steps.style.cssText = "transform:translateX("+(stepWidth)+"px);"
// Remove the .active class from the active step
activeStep.classList.remove('active');
// Add the .active class to the newly active step
previousStep.classList.add('active');
console.log(stepWidth);
};
function regress(){
// Look for the active step
let activeStep = document.querySelector('.active');
// Look for the previous step
let previousStep = activeStep.previousSibling;
// Get the width of the element
stepWidth = stepWidth - previousStep.clientWidth - 32;
// Step backwards
stepPlace--;
// Count the steps
let stepCount = document.getElementsByClassName('step').length;
// Calculate the new width of the meter
meterWidth = ((100/stepCount)*stepPlace);
// Update the styling to show the new meter width
progressMeter.style.cssText = "width:"+meterWidth+"%;"
// Slide the text to the left using the width of the step element
steps.style.cssText = "transform:translateX(-"+(stepWidth)+"px);" // <-- here
// Remove the .active class from the active step
activeStep.classList.remove('active');
// Add the .active class to the newly active step
previousStep.classList.add('active');
console.log(stepWidth);
};