如何使用jQuery UI .slider()制作垂直滚动条?

时间:2011-09-07 21:07:11

标签: jquery slider scrollbar

<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <style type="text/css">
    #slider { margin: 10px; }
  </style>
  <script>
    $(document).ready(function() {
        $("#slider").slider( "option", "orientation" );

        //getter
        var orientation = $( "#slider" ).slider( "option", "orientation" );
        //setter
        $( "#slider" ).slider( "option", "orientation", 'vertical' );
    });
  </script>
</head>
<body style="font-size:62.5%;">

<div id="slider"></div>

</body>
</html>

我在

中添加了
    //getter
    var orientation = $( "#slider" ).slider( "option", "orientation" );
    //setter
    $( "#slider" ).slider( "option", "orientation", 'vertical' );

部分代码希望让演示页面的滚动条显示为垂直,但它所做的只是隐藏已经存在的水平滚动条,现在我只有一个空白页面。我究竟如何实现垂直滚动条选项?我不太了解documentation page.

上列出的说明

1 个答案:

答案 0 :(得分:4)

我认为this部分文档非常明确:

    $( "#slider-vertical" ).slider({
        orientation: "vertical",
        range: "min",
        min: 0,
        max: 100,
        value: 60,
        slide: function( event, ui ) {
            $( "#amount" ).val( ui.value );
        }
    });

您必须执行$( "#slider" ).slider( { "orientation" : "vertical"} );才能创建垂直滑块。