Touch screen style horizontal scrolling (click and drag) menu on Pcs

Asked

Viewed 842 times

1

Using the menu below, it is possible to make it slider as in mobile phones (without having to use the scroll bar, just by clicking and dragging)?

ul.marcadores {white-space:nowrap; overflow-x:auto; background-color:#2D2D2D; width:300px}
ul.marcadores li {display:inline-block; float:none; margin:10px; padding:4px}
ul.marcadores li:hover {border-bottom:1px solid #FFFFFF; padding-bottom:1px}
ul.marcadores a {color:#FFFFFF; font-size:12px; font-family:Open Sans; text-transform:uppercase; font-weight:bold; text-decoration:none}
<ul class='marcadores'>
<li><a href='#'>Link 0</a></li>
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
<li><a href='#'>Link 3</a></li>
<li><a href='#'>Link 4</a></li>
<li><a href='#'>Link 5</a></li>
</ul>

1 answer

1


Yes, but for this you will need a javascript knowledge, you can use jQuery.

This link has all the Draggable documentation that you need to use https://jqueryui.com/draggable/

The first example shown on the home page is similar to what you need, in your case is to block the movement on the Y axis, allowing the user to make the move only on the X axis. I gave a modified one in the code to better illustrate.

$( function() {
    $( "#draggable" ).draggable({
     containment: 'parent'
     });
});
  .divPai{
    width: 100%;
    height: 150px;
    background: black;
  }
  
  #draggable { 
    width: 150px; 
    height: 150px; 
    background: red
  }
<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>

<div class="divPai">
  <div id="draggable">
    <p>Drag me around</p>
  </div>
</div>
  

  • 1

    It worked, @Pedro Junior! I was just wondering how to block the movement on the Y axis, but otherwise, it’s what I needed! Thank you! I will continue in the material research here!

  • So, you can do like I did in the example, in the divPai you arrow a height, and in the son the same height, in your case create a div father, and the tag ul will be the daughter, and you can put the option containment: 'Parent', what will make daughter move inside the father

Browser other questions tagged

You are not signed in. Login or sign up in order to post.