2011-09-05 74 views
2

我在我的網站上有this slider。我想將滑塊移至360度。我如何更改以下腳本來執行此操作?jQuery圓形滑塊?

$(document).ready(function() { 
    /*Slider */ 
    $('.slider-input').each(function() { 
     var currVal = $(this).val(); 
     if(currVal < 0){ 
      currVal = 0; 
     } 
     $(this).parent().children('.slider-content').slider({ 
      'animate': true, 
      'min': -1, 
      'max': 201, 
      'value' : 201, 
      'orientation' : 'vertical', 
      'stop': function(e, ui){ 
       //$(this).prev('.slider-input').val(ui.value); //Set actual input field val, done during slide instead 

       //pop handle back to top if we went out of bounds at bottom 
       /* 
       if (ui.value == -1) { 
        ui.value = 201; 
        $(this).children('.ui-slider-handle').css('bottom','100%'); 
       } 
       */ 
      }, 
      'slide': function(e, ui){ 
       var percentLeft; 
       var submitValue; 
       var Y = ui.value - 100; //Find center of Circle (We're using a max value and height of 200) 
       var R = 100; //Circle's radius 
       var skip = false; 

       $(this).children('.ui-slider-handle').attr('href',' UI.val = ' + ui.value); 

       //Show default/disabled/out of bounds state 
       if (ui.value > 0 && ui.value < 201) { //if in the valid slide rang 
        $(this).children('.ui-slider-handle').addClass('is-active'); 
       } 
       else { 
        $(this).children('.ui-slider-handle').removeClass('is-active'); 
       } 

       //Calculate slider's path on circle, put it there, by setting background-position 
       if (ui.value >= 0 && ui.value <= 200) { //if in valid range, these are one inside the min and max 
        var X = Math.sqrt((R*R) - (Y*Y)); //X^2 + Y^2 = R^2. Find X. 
        if (X == 'NaN') { 
         percentLeft = 0; 
        } 
        else { 
         percentLeft = X; 
        } 
       } 
       else if (ui.value == -1 || ui.value == 201) { 
        percentLeft = 0; 
        skip = true; 
       } 
       else { 
        percentLeft = 0; 
       } 

       //Move handle 
       if (percentLeft > 100) { percentLeft = 100; } 
       $(this).children('.ui-slider-handle').css('background-position',percentLeft +'% 100%'); //set css sprite 

       //Figure out and set input value 
       if (skip == true) { 
        submitValue = 'keine Seite'; 
        $(this).children('.ui-slider-handle').css('background-position',percentLeft +'% 0%'); //reset css sprite 
       } 
       else { 
        submitValue = Math.round(ui.value/2); //Clamp input value to range 0 - 100 
       } 
       $('#display-only input').val(submitValue); //display selected value, demo only 
       $('#slider-display').text(submitValue); //display selected value, demo only 
       $(this).prev('.slider-input').val(ui.value); //Set actual input field val. jQuery UI hid it for us, but it will be submitted. 
      } 
     }); 
    }); 
}); 

滑塊的圖像也必須旋轉360度。

+0

您能否更具體地說明'move'和'滑塊圖形'的含義? – Bojangles

+0

他想旋轉aka移動半徑拐角處的刻度線,移動一圈即可。他確實提供了滑塊的鏈接。 – Rumplin

+0

@nayish 360度=全圓FYI。 – Rumplin

回答

0

要計算一個圓,可以使用下面的公式。

precenttop = (-(cos(ui.value/(100/pi))-1))*50) 
percentleft = (sin(ui.value/(100/pi))*50)+50 

那麼就應該周圍一圈旋轉.. 201 FO ui一個值將在相同的位置,1和-1是相同的199

的上述的解釋是:

cos(ui.value/(100/pi)) <-- ui value ranges from 0 to 200 but the cosine 
          period is 2pi so devide the ui value so its 
          somewhere between 0 and 2pi 
-1      <-- result ranges from 1 to -1 and i prefer 0 to 2 so 
          minus 1 makes it 0 to -2 therefore 
-()     <-- we invert the whole... now it 0 to 2 
*50     <-- since you are using percent 0*50 = 0 and 2*50 = 100 
          ergo it now bounces between 0 and 100. 

爲罪,這幾乎是相同的,除了這裏,我們確實希望得到的結果是-1和1之間,我們只是乘以50(-50〜50),並添加50(0 - 100) 。

現在對於ui.value等於0 percenttop結果將是0和percentleft將是50而在

ui.value = 100 50 150 200 
top =  100 50 50 0 
left =  50 100 0 50 

人機工程學:圓。

+0

感謝您的回答。我嘗試你的方式。是否有可能更改WordPress的滑塊,用戶把它轉到他想要的頁面?他會自動跳轉到博客頁面?感謝carsten – Carsten