2013-08-25 81 views
2

我正在使用jQuery UI滑塊。如果我將手柄的高度改爲超過標準(20像素),然後單擊滑塊手柄並將其向任何方向移動 - 滑塊的手柄跳躍幾個像素。jQuery UI滑塊句柄跳轉

我希望它不會反彈。

jsFiddle Example

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8" /> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> 
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> 
    <style type="text/css"> 
    .ui-slider .ui-slider-handle{ 
     height: 30px; 
    } 
    </style> 
    <script> 
    $(function() { 
    $(".slider-vertical").slider({ 
     orientation: "vertical", 
    }); 
    }); 
    </script> 
</head> 
<body> 
    <div class="slider-vertical"></div> 
</body> 
</html> 

回答

7

你只需要改變.ui-slider-handle下邊距像這樣:

Working Example

.ui-slider .ui-slider-handle{ 
    height: 30px; 
    margin-bottom:-15px; 
} 

手柄的位置與高度。默認情況下,手柄的高度爲1.2em,並將手柄置於其位置的中心,因此會給出1/2或-0.6em的負底部邊距,因此如果您需要重新調整手柄的大小,則必須調整底部邊緣也是如此。

基本上margin-bottom = 0 - height/2

+0

非常好,非常感謝! 我一直在尋找解決這個問題約20個小時,解決方案變得如此簡單。 :))) –

+0

找到了答案。主題已關閉。 –

+0

優秀的答案。我的具體問題是旋轉90度,因此左右滑動滑塊。同樣的答案tho。 margin-left = 0 - width/2 – Will