gpt4 book ai didi

javascript - -moz-linear-gradient 在 JQuery Slider 上添加 -webkit-linear-gradient 时中断

转载 作者:行者123 更新时间:2023-11-28 12:22:39 27 4
gpt4 key购买 nike

TL;DR -webkit-linear-gradient 正在打破 -moz-linear-gradient

听说是个难题,我使用的是带有两个 handle 的 Jquery Slider 插件,我使用渐变作为背景颜色,为外部范围提供一些颜色。我想要做的是在 slider 移动时更新渐变的百分比。它适用于 Chrome/Safari,但在同时使用 -moz 和 -webkit 标签时不适用于 Firefox。该值是从第一个 slider 的位置拉出的。

当我只有 -moz-linear-gradient 标签时它可以工作,但是一旦我添加 -webkit-linear-gradient 标签它就会在 Firefox 中中断。

这是代码

HTML:

<div id="traffic-allocation">
<h4 id="traffic-allocation-hed">Traffic Allocation <small>Change by dragging handles right or left and applying changes</small></h4>
<div class="slideContainer">
<div id="slider-direct" class="slider"></div>
</div>
</div>

<div class="labelBox">
<div class="control-box" id="control-box-direct">
<input id="control-direct" type="text" value="35%" class="allocation-control" />
<div class='allocation-control-wrapper'>
<h4 class="variantLabel mycontrol-label" id="mycontrol-label-direct">Control: </h4>
</div>
</div>
</div>

JavaScript:

$(function() {
$( '.slider' ).slider({
range: true,
values: [35, 70],
min: 0,
max: 100,
step: 5,
slide: function( e, ui ) {

//Derive calling (class selector) element's ID and set the IDs for its "companion" value displays:
theSegment = e.target.id.slice(7);
theControl = '#control-' + theSegment;

$( theControl ).val( ui.values[ 0 ] + '%' );

var slidercolor = $('#control-direct').val();
$('.ui-slider-horizontal').css({
background: '#0e76bc', /* Old browsers */
background: 'linear-gradient(to right, #0e76bc '+slidercolor+',#e78f08 '+slidercolor+')' ,/* W3C */
background: '-moz-linear-gradient(left, #0e76bc '+slidercolor+', #e78f08 '+slidercolor+')', /* FF3.6+ */
background: '-webkit-linear-gradient(left, #0e76bc '+slidercolor+',#e78f08 '+slidercolor+')' /* Chrome10+,Safari5.1+ */

})
}
});

CSS:

h1 {
font-family: Helvetica, Arial;
font-weight: bold;
font-size: 18px;
}

body, p{
font-family: Helvetica, Arial;
}

.ui-slider-horizontal{
background: '#0e76bc', /* Old browsers */
background: linear-gradient(to right, #0e76bc 50%,#e78f08 50%); /* W3C *
background: -moz-linear-gradient(left, #0e76bc 50%, #e78f08 50%); /* FF3.6+ */
background: -webkit-linear-gradient(left, #0e76bc 50%,#e78f08 50%); /* Chrome10+,Safari5.1+ */

}
.ui-widget-header {
background: none repeat scroll 0 0 #292668;
border: 1px solid #CCCCCC;
color: #292668;
font-weight: bold;
}

这是一个链接,可以查看正在发生的事情和 css,因为其中有很多 :)。 (在 chrome/safari 中打开看看它应该做什么,在 firefox 中打开看看它坏了)

http://jsfiddle.net/DrewLandgrave/bep9A/

提前谢谢你:)

最佳答案

您只能为给定元素的任何单个样式属性设置一个值。您得到的是您在 CSS 文件中所做的,但这不是 .css() 方法所做的。它直接在每个受影响的 DOM 元素上扰乱了 style 对象的属性。因此,当您设置“-moz-linear-gradient”时,您将清除“linear-gradient”,而当您设置它时,您将清除简单的颜色设置。

按类或其他方式在 CSS 中设置您的样式,然后在您想选择一种设置或另一种设置时在 JavaScript 中设置类。

关于javascript - -moz-linear-gradient 在 JQuery Slider 上添加 -webkit-linear-gradient 时中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12201355/

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