2016-03-14 69 views
0

我想改變一個jQuery UI的滑塊,與供應商前綴的背景CSS。我正在使用線性漸變。我最需要所有瀏覽器的支持。我已經在css樣式表中設置了一些帶有供應商前綴的css,並且我想通過javascript更改漸變。我需要的CSS這個前綴5如何使用供應商前綴修改jquery的jquery?

  • -webkit-
  • -moz-
  • -O-
  • -ms-
  • -khtml-

    這裏是jsfiddle

    $(function() { 
        $("#range-slider1").slider({ 
         range:false, 
         min: 0, 
         max: 360, 
         value: 0, 
         slide: function(event, ui) { 
         var hue = ui.value, 
          sat = $('#range-slider2').slider('value'), 
          light = $('#range-slider3').slider('value'), 
          alpha = $('#range-slider4').slider('value'), 
          hsla = "hsla(" + hue + "," + sat + "%, " + light + "%, " + alpha + ")", 
         satRangeW = "-webkit-linear-gradient(left, hsla(" + ui.value + ", 0%, 50%, 1),hsla(" + ui.value + ", 20%, 50%, 1),hsla(" + ui.value + ", 40%, 50%, 1),hsla(" + ui.value + ", 60%, 50%, 1),hsla(" + ui.value + ", 80%, 50%, 1),hsla(" + ui.value + ", 100%, 50%, 1))", 
         satRangeMo = "-moz-linear-gradient(left, hsla(" + ui.value + ", 0%, 50%, 1),hsla(" + ui.value + ", 20%, 50%, 1),hsla(" + ui.value + ", 40%, 50%, 1),hsla(" + ui.value + ", 60%, 50%, 1),hsla(" + ui.value + ", 80%, 50%, 1),hsla(" + ui.value + ", 100%, 50%, 1))"; 
         $("#slidevalue").text(hsla); 
         $(".slidevalue").css('background-color', hsla); 
         $("#range-slider2").css("background", satRangeW); 
    
         } 
        }); 
    
        $("#range-slider2").slider({ 
         range:false, 
         min: 0, 
         max: 100, 
         value: 100, 
         slide: function(event, ui) { 
          var hue = $('#range-slider1').slider('value'), 
           sat = ui.value, 
           light = $('#range-slider3').slider('value'), 
           alpha = $('#range-slider4').slider('value'), 
           hsla = "hsla(" + hue + "," + sat + "%, " + light + "%, " + alpha + ")"; 
          $("#slidevalue").text(hsla); 
          $(".slidevalue").css('background-color', hsla); 
    
         } 
        }); 
        $("#range-slider3").slider({ 
         range:false, 
         min: 0, 
         max: 100, 
         value: 50, 
         slide: function(event, ui) { 
          var hue = $('#range-slider1').slider('value'), 
           sat = $('#range-slider2').slider('value'), 
           light = ui.value, 
           alpha = $('#range-slider4').slider('value'), 
           hsla = "hsla(" + hue + "," + sat + "%, " + light + "%, " + alpha + ")"; 
          $("#slidevalue").text(hsla); 
          $(".slidevalue").css('background-color', hsla); 
    
         } 
        }); 
        $("#range-slider4").slider({ 
         range:false, 
         min: 0, 
         max: 1, 
         value: 1, 
         step: 0.01, 
         slide: function(event, ui) { 
          var hue = $('#range-slider1').slider('value'), 
           sat = $('#range-slider2').slider('value'), 
           light = $('#range-slider3').slider('value'), 
           alpha = ui.value, 
           hsla = "hsla(" + hue + "," + sat + "%, " + light + "%, " + alpha + ")"; 
          $("#slidevalue").text(hsla); 
          $(".slidevalue").css('background-color', hsla); 
    
         } 
        }); 
    }); 
    
+0

http://stackoverflow.com/questions/17487716/does-css-automatically-add-vendor-prefixes/17487728(賣主前綴添加用'的CSS()') – Shanimal

+0

我看到了這個問題。沒有任何插件可以嗎? –

+0

'.css'是jquery的一部分,我不明白? – Shanimal

回答

0

您已經展示瞭如何通過jQuery修改CSS,例如代碼:

$(".slidevalue").css('background-color', hsla); 

你會使用相同的語法,只是提供CSS屬性作爲第一個參數和值作爲第二。例如:

$(".slidevalue").css('-webkit-border-radius', "5px"); 
+0

我正在使用線性漸變。 –

+0

沒關係。只需使用-webkit-linear-gradient-即可。無論您需要哪種CSS屬性,只需在第一個參數中將其作爲字符串提供即可。 –

相關問題