0

Please help me how can I stop slider handle stop at the end of slider border.

enter image description here

DEMO:

body{
    padding:50px
}
#slider{
    height:50px;
    border-radius:50px;
    border-color:#1C2128;
}
#slider span {
    height: 50px;
    border-radius: 50px;
    top: 0;
    width: 80px;
    margin-left: 0;
    border:0;
    background:#69B253;
}
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery UI Slider - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
    $( function() {
        $( "#slider" ).slider();
    });
    </script>
</head>
<body>
 
<div id="slider"></div>
 
</body>
</html>

I try many solutions but dont work.

How can I straight add styling to that slider to stop handle in right border? I need universal function to this. Please help me.

Ignacio Ara
  • 2,476
  • 2
  • 26
  • 37
Rafal
  • 35
  • 1
  • 3

1 Answers1

0

Maybe this is not perfect solution

I used change event to detect the value from slider

body{padding:50px}
#slider{height:50px;border-radius:50px;border-color:#1C2128;}
#slider span {
height: 50px;
border-radius: 50px;
top: 0;
width: 80px;
margin-left: 0;
border:0;
background:#69B253;
}

#slider {
  overflow: hidden;
}

#slider.finished span {
  margin-left: -80px;
}
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Slider - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#slider" ).slider({
      change: function(event, ui) {
        console.log(ui.value);
        if (ui.value >= 80) {
          $( "#slider" ).addClass('finished')
        } else {
          $("#slider").removeClass('finished')
        }
      }
    });
    
  } );
  </script>
</head>
<body>
 
<div id="slider"></div>
 
 
</body>
</html>
Tan Duong
  • 2,124
  • 1
  • 11
  • 17