Selectable icons by dragging cursor

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Selectable icons by dragging cursor



I want to be able to select multiple items as you would on your PC desktop, where you drag your cursor and the transparent box goes over the icons and selects them like this:
Desktop icon select.gif



except I need it to be able to start the selection box from anywhere, not have to start dragging from on top of an icon like the above GIF shown at the end of the GIF.



here's the code to modify (I got it off http://jqueryui.com/selectable/): >>uses JQuery<<




<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Selectable - 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">

<style>
#feedback
font-size: 1.4em;


#selectable .ui-selecting
background: #FECA40;


#selectable .ui-selected
background: #F39814;
color: white;


#selectable
list-style-type: none;
margin: 0;
padding: 0;
width: 60%;


#selectable li
margin: 3px;
padding: 0.4em;
font-size: 1.4em;
height: 18px;

</style>
<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()
$("#selectable").selectable();
);
</script>
</head>

<body>

<ol id="selectable">
<li class="ui-widget-content">Item 1</li>
<li class="ui-widget-content">Item 2</li>
<li class="ui-widget-content">Item 3</li>
<li class="ui-widget-content">Item 4</li>
<li class="ui-widget-content">Item 5</li>
<li class="ui-widget-content">Item 6</li>
<li class="ui-widget-content">Item 7</li>
</ol>


</body>

</html>




2 Answers
2



You simply need to change the selector on which you have your .selectable() hooked up to.
In the following example I modify it to run off of <body> with $("body").selectable(). Note that if you want to only be able to select the #selectable elements, you can make use of filter in the .selectable() function, such as with filter: "#selectable > li":


.selectable()


<body>


$("body").selectable()


#selectable


filter


.selectable()


filter: "#selectable > li"




$(function()
$("body").selectable(
filter: "#selectable > li"
);
);


#feedback
font-size: 1.4em;


#selectable .ui-selecting
background: #FECA40;


#selectable .ui-selected
background: #F39814;
color: white;


#selectable
list-style-type: none;
margin: 0;
padding: 0;
width: 60%;


#selectable li
margin: 3px;
padding: 0.4em;
font-size: 1.4em;
height: 18px;


<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.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>

<ol id="selectable">
<li class="ui-widget-content">Item 1</li>
<li class="ui-widget-content">Item 2</li>
<li class="ui-widget-content">Item 3</li>
<li class="ui-widget-content">Item 4</li>
<li class="ui-widget-content">Item 5</li>
<li class="ui-widget-content">Item 6</li>
<li class="ui-widget-content">Item 7</li>
</ol>



Maybe you need to have these changes of css on #selectable


#selectable


box-sizing: border-box;
padding: 0 40% 0 0;
width: 100%;




<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Selectable - 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">

<style>
#feedback
font-size: 1.4em;


#selectable .ui-selecting
background: #FECA40;


#selectable .ui-selected
background: #F39814;
color: white;


#selectable
box-sizing: border-box;
list-style-type: none;
margin: 0;
padding: 0 40% 0 0;
width: 100%;


#selectable li
margin: 3px;
padding: 0.4em;
font-size: 1.4em;
height: 18px;

</style>
<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()
$("#selectable").selectable();
);
</script>
</head>

<body>

<ol id="selectable">
<li class="ui-widget-content">Item 1</li>
<li class="ui-widget-content">Item 2</li>
<li class="ui-widget-content">Item 3</li>
<li class="ui-widget-content">Item 4</li>
<li class="ui-widget-content">Item 5</li>
<li class="ui-widget-content">Item 6</li>
<li class="ui-widget-content">Item 7</li>
</ol>


</body>

</html>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard