2013-08-25 80 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