gpt4 book ai didi

范围输入的 JavaScript 位置问题

转载 作者:行者123 更新时间:2023-11-28 01:44:04 25 4
gpt4 key购买 nike

大家下午好

我被一个 JavaScript/CSS/HTML 问题困住了,让我花点时间解释一下

  1. 我为我运行的网站编写了一个报价系统 ( http://www.liquidationmadeeasy.co.uk/quote.html )

  2. 我遵循了一个使用框架集的示例,以便为报价创建不同的阶段,但没有导航到单独的页面。效果很好。

  3. 在每个字段集上,我引入了一个范围输入。我将执行一个计算,它会强制用户输入一个数值。

  4. 然后我按照另一个教程介绍了一个显示范围控件的选定值的气泡。

  5. 当页面加载时,它会在每个范围控件的一侧绘制气泡。然而,当我导航到第二个框架集时,所有元素的气泡都绘制在页面中间(不在正确的位置)并且全部在彼此之上。

  6. 当用户从范围控件中选择一个值时,气泡会在正确的位置重新绘制。

我想在用户离开第一阶段时自动重绘报价第二阶段的所有气泡。

我假设这是失败的,因为我重置了仅在用户更改值时触发的更改事件的范围输入值

谁能给我指出正确的方向

HTML

    <form id="msform" method="post" action="quoteresult.php">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Debts</li>
<li>Assets</li>
<li>Contact</li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title">What You Owe</h2>
<h3 class="fs-subtitle">Your companys financial possition</h3>
<label for="overdraft">Overdraft:</label>
<input type="range" name="overdraft" id="overdraft" value=0 min=0 max=1000000 step="500" />
<output for="overdraft">1</output>
<label for="vat">VAT:</label>
<input type="range" name="vat" id="vat" value=0 min=0 max=1000000 step="500" />
<output for="vat">1</output>
<label for="paye">PAYE:</label>
<input type="range" name="paye" value=0 min=0 max=1000000 step="500"/>
<output for="paye">1</output>
<label for="corporationtax">Corporation Tax:</label>
<input type="range" name="corporationtax" value=0 min=0 max=1000000 step="500" />
<output for="corporationtax">1</output>
<label for="tradecreditors">Trade Creditors:</label>
<input type="range" name="tradecreditors" value=0 min=0 max=1000000 step="500" />
<output for="tradecreditors">1</output>
<label for="rent">Rent:</label>
<input type="range" name="rent" value=0 min=0 max=1000000 step="500" />
<output for="rent">1</output>
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Asset Values</h2>
<h3 class="fs-subtitle">What are you assets worth?</h3>
<label for="debtors">Debtors:</label>
<input type="range" name="debtors" value=0 min=0 max=1000000 step="500" />
<output for="debtors">1</output>
<label for="fixtures">Fixtures:</label>
<input type="range" name="fixtures" value=0 min=0 max=1000000 step="500"/>
<output for="fixtures">1</output>
<label for="stock">Stock:</label>
<input type="range" name="stock" value=0 min=0 max=1000000 step="500" />
<output for="stock">1</output>
<label for="vehicles">Vehicles:</label>
<input type="range" name="vehicles" value=0 min=0 max=1000000 step="500" />
<output for="vehicles">1</output>
<label for="cash">Cash:</label>
<input type="range" name="cash" value=0 min=0 max=1000000 step="500" />
<output for="cash">1</output>
<label for="plant">Plant/Machinery:</label>
<input type="range" name="plant" value=0 min=0 max=1000000 step="500"/>
<output for="plant">1</output>
<label for="property">Property:</label>
<input type="range" name="property" value=0 min=0 max=1000000 step="500" />
<output for="property">1</output>
<label for="other">Other:</label>
<input type="range" name="other" value=0 min=0 max=1000000 step="500" />
<output for="other">1</output>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Details</h2>
<h3 class="fs-subtitle">We will never sell it</h3>
<input type="text" name="fname" placeholder="First Name" />
<input type="text" name="lname" placeholder="Last Name" />
<input type="text" name="company" placeholder="Company Name" />
<input type="text" name="phone" placeholder="Phone" />
<input type="text" name="email" placeholder="Email" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="submit action-button" value="Submit" />
</fieldset>
</form>

CSS

    /*form styles*/
#msform {
width: 400px;
margin: 50px auto;
text-align: center;
position: relative;
}
#msform fieldset {
background: white;
border: 0 none;
border-radius: 3px;
box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
padding: 20px 30px;

box-sizing: border-box;
width: 80%;
margin: 0 10%;

/*stacking fieldsets above each other*/
position: absolute;
}
/*Hide all except first fieldset*/
#msform fieldset:not(:first-of-type) {
display: none;
}
/*inputs*/
#msform input, #msform textarea {
padding: 15px;
border: 1px solid #ccc;
border-radius: 3px;
margin-bottom: 10px;
width: 100%;
box-sizing: border-box;
font-family: montserrat;
color: #2C3E50;
font-size: 13px;
}
/*buttons*/
#msform .action-button {
width: 100px;
background: #27AE60;
font-weight: bold;
color: white;
border: 0 none;
border-radius: 1px;
cursor: pointer;
padding: 10px 5px;
margin: 10px 5px;
}
#msform .action-button:hover, #msform .action-button:focus {
box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60;
}
/*headings*/
.fs-title {
font-size: 15px;
text-transform: uppercase;
color: #2C3E50;
margin-bottom: 10px;
}
.fs-subtitle {
font-weight: normal;
font-size: 13px;
color: #666;
margin-bottom: 20px;
}
/*progressbar*/
#progressbar {
margin-bottom: 30px;
overflow: hidden;
/*CSS counters to number the steps*/
counter-reset: step;
}
#progressbar li {
list-style-type: none;
color: white;
text-transform: uppercase;
font-size: 9px;
width: 33.33%;
float: left;
position: relative;
}
#progressbar li:before {
content: counter(step);
counter-increment: step;
width: 20px;
line-height: 20px;
display: block;
font-size: 10px;
color: #333;
background: white;
border-radius: 3px;
margin: 0 auto 5px auto;
}
/*progressbar connectors*/
#progressbar li:after {
content: '';
width: 100%;
height: 2px;
background: white;
position: absolute;
left: -50%;
top: 9px;
z-index: -1; /*put it behind the numbers*/
}
#progressbar li:first-child:after {
/*connector not needed before the first step*/
content: none;
}
/*marking active/completed steps green*/
/*The number of the step and the connector before it = green*/
#progressbar li.active:before, #progressbar li.active:after{
background: #27AE60;
color: white;
}

JavaScript

//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var left, opacity, scale; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next").click(function(){
if(animating) return false;
animating = true;

current_fs = $(this).parent();
next_fs = $(this).parent().next();

//activate next step on progressbar using the index of next_fs
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");

//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({'transform': 'scale('+scale+')'});
next_fs.css({'left': left, 'opacity': opacity});
},
duration: 800,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});

$(".previous").click(function(){
if(animating) return false;
animating = true;

current_fs = $(this).parent();
previous_fs = $(this).parent().prev();

//de-activate current step on progressbar
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale previous_fs from 80% to 100%
scale = 0.8 + (1 - now) * 0.2;
//2. take current_fs to the right(50%) - from 0%
left = ((1-now) * 50)+"%";
//3. increase opacity of previous_fs to 1 as it moves in
opacity = 1 - now;
current_fs.css({'left': left});
previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
this.redraw();
},
duration: 800,
complete: function(){
current_fs.hide();
animating = false;

},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});

$(".submit").click(function(){
document.getElementById("msform").submit();

return false;
})

$(function() {
var el, newPoint, newPlace, offset, newTop;
$("input[type='range']").change(function() {
el = $(this);
width = el.width();
newPoint = (el.val() - el.attr("min")) / (el.attr("max") - el.attr("min"));
offset = -1.3;
newTop = el.position().top - 10;
newLeft = el.position().left + width + 10;
if (newPoint < 0) { newPlace = 0; }
else if (newPoint > 1) { newPlace = width; }
else { newPlace = width * newPoint + offset; offset -= newPoint;}
el
.next("output")
.css({
left: newLeft + "px",
top: newTop + "px"
})
.text(el.val());
})
.trigger('change');
});

最佳答案

这不是建议的解决方案,但我必须这样发布它,以便我可以上传我的结果的屏幕截图。我逐字复制了您的 HTML、CSS 和 JS(当然,我必须适本地包装 HTML),但我没有遇到您描述的错误。我尝试使用两个不同的 jQuery CDN 文件:

以下是在 Firefox 29.0.1、Chrome 35、Safari 6.1.4 和 IE10 中呈现的第二阶段“ Assets 值(value)”的屏幕截图。前三个在 Mac OS X 10.7.5 上,后者在 VirtualBox/上运行的 Windows 8 VM 上。顺序是 Firefox、Chrome、Safari、IE:

Firefox 29.0.1

Chrome 35

Safari 6.1.4

IE10

如您所见,除 Firefox 外,所有浏览器的渲染都在某种程度上被破坏,但您描述的错误并未出现。我还注意到您链接到的网站:http://www.liquidationmadeeasy.co.uk/quote.html...在 Firefox 29 中似乎也能正常工作:

Live site

您想发布您用于测试的确切浏览器版本吗?


附言

与您的问题无关,但请注意,您的大多数 HTML 元素都有“for”属性,这些属性指向“name”属性而不是“id”属性。参见 <label> element in MDN documentation .

以下标签就是这种情况:

第一个字段集:

    <label for="paye">PAYE:</label>
<input type="range" name="paye" value=0 min=0 max=1000000 step="500"/>
<output for="paye">1</output>
<label for="corporationtax">Corporation Tax:</label>
<input type="range" name="corporationtax" value=0 min=0 max=1000000 step="500" />
<output for="corporationtax">1</output>
<label for="tradecreditors">Trade Creditors:</label>
<input type="range" name="tradecreditors" value=0 min=0 max=1000000 step="500" />
<output for="tradecreditors">1</output>
<label for="rent">Rent:</label>
<input type="range" name="rent" value=0 min=0 max=1000000 step="500" />

第二个字段集:

    <label for="debtors">Debtors:</label>
<input type="range" name="debtors" value=0 min=0 max=1000000 step="500" />
<output for="debtors">1</output>
<label for="fixtures">Fixtures:</label>
<input type="range" name="fixtures" value=0 min=0 max=1000000 step="500"/>
<output for="fixtures">1</output>
<label for="stock">Stock:</label>
<input type="range" name="stock" value=0 min=0 max=1000000 step="500" />
<output for="stock">1</output>
<label for="vehicles">Vehicles:</label>
<input type="range" name="vehicles" value=0 min=0 max=1000000 step="500" />
<output for="vehicles">1</output>
<label for="cash">Cash:</label>
<input type="range" name="cash" value=0 min=0 max=1000000 step="500" />
<output for="cash">1</output>
<label for="plant">Plant/Machinery:</label>
<input type="range" name="plant" value=0 min=0 max=1000000 step="500"/>
<output for="plant">1</output>
<label for="property">Property:</label>
<input type="range" name="property" value=0 min=0 max=1000000 step="500" />
<output for="property">1</output>
<label for="other">Other:</label>
<input type="range" name="other" value=0 min=0 max=1000000 step="500" />

关于范围输入的 JavaScript 位置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23872497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com