Jquery sortable / scrollable tabs jumping - javascript

I have some sortable / scrollable tabs but the sibling tabs keep jumping when I start sorting.
The axis is set to 'x' yet when sorting you can slightly drag up and down, which is where you will see the jumping.
Normally I would fix this by setting float: left; but this causes each tab to be in it's own "row" somehow.
How can I stop this "jumping" issue in sortable / scrollable tabs?
$('.data_tab_tabs').sortable({
items: '.data_tab',
axis: 'x',
containment: 'parent',
helper: 'clone',
appendTo: 'parent',
forcePlaceholderSize: true,
tolerance: 'pointer',
});
.data_tab_container {
width: 500px;
height: fit-content;
position: relative;
}
.data_tab_tabs {
height: 40px;
width: fit-content;
max-width: 100%;
position: relative;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.data_tab {
border: 1px solid #ddd;
display: inline-block;
width: fit-content;
height: 100%;
border-radius: 5px 5px 0 0;
padding: 10px 10px;
background: #f1f3f6;
cursor: pointer;
position: relative;
z-index: 10;
margin-right: 4px;
/* float: left; */
font-weight: 600;
}
.data_tab * {
display: inline-block;
}
.data_tab.active_data_tab {
background: #fff;
border-bottom: 1px solid #fff;
}
/* width */
.data_tab_tabs::-webkit-scrollbar {
height: 6px !important;
}
/* Track */
.data_tab_tabs::-webkit-scrollbar-track {
background: transparent !important;
}
/* Handle */
.data_tab_tabs::-webkit-scrollbar-thumb {
background: #ddd !important;
border-radius: 3px;
}
/* Handle on hover */
.data_tab_tabs::-webkit-scrollbar-thumb:hover {
background: #ccc !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="data_tab_container">
<div class="data_tab_tabs">
<div class="data_tab active_data_tab" data-tab="headers" data-level="1">Here is something</div>
<div class="data_tab" data-tab="body" data-level="1">Here is something else</div>
<div class="data_tab" data-tab="footers" data-level="1">Here is something else again</div>
</div>
</div>

Yes, float:left; will fix your sorting problem but it will open another problem where 3rd tab goes in new line.
It's because there is not enough space for 3rd tab. If you remove width: 500px; from .data_tab_container style than you will see its working fine.
See the Snippet below:
$('.data_tab_tabs').sortable({
items: '.data_tab',
axis: 'x',
containment: 'parent',
helper: 'clone',
appendTo: 'parent',
forcePlaceholderSize: true,
tolerance: 'pointer',
});
.data_tab_container {
/*width: 500px;*/
height: fit-content;
position: relative;
}
.data_tab_tabs {
height: 40px;
width: fit-content;
max-width: 100%;
position: relative;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.data_tab {
border: 1px solid #ddd;
display: inline-block;
width: fit-content;
height: 100%;
border-radius: 5px 5px 0 0;
padding: 10px 10px;
background: #f1f3f6;
cursor: pointer;
position: relative;
z-index: 10;
margin-right: 4px;
float: left;
font-weight: 600;
}
.data_tab * {
display: inline-block;
}
.data_tab.active_data_tab {
background: #fff;
border-bottom: 1px solid #fff;
}
/* width */
.data_tab_tabs::-webkit-scrollbar {
height: 6px !important;
}
/* Track */
.data_tab_tabs::-webkit-scrollbar-track {
background: transparent !important;
}
/* Handle */
.data_tab_tabs::-webkit-scrollbar-thumb {
background: #ddd !important;
border-radius: 3px;
}
/* Handle on hover */
.data_tab_tabs::-webkit-scrollbar-thumb:hover {
background: #ccc !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="data_tab_container">
<div class="data_tab_tabs">
<div class="data_tab active_data_tab" data-tab="headers" data-level="1">Here is something</div>
<div class="data_tab" data-tab="body" data-level="1">Here is something else</div>
<div class="data_tab" data-tab="footers" data-level="1">Here is something else again</div>
</div>
</div>
Update 2
Have fixed it by adding 1px of height in placeholder (which jQuery adds when you start drag). I think its an open bug in jQuery..
here is a fix
.ui-sortable-placeholder {
display: inline-block;
height: 1px;
}
See the Snippet below:
$('.data_tab_tabs').sortable({
items: '.data_tab',
axis: 'x',
containment: 'parent',
helper: 'clone',
appendTo: 'parent',
forcePlaceholderSize: true,
tolerance: 'pointer',
start: function(event, ui) {
ui.placeholder.html(' ');
}
});
.data_tab_container {
width: 500px;
height: fit-content;
position: relative;
}
.data_tab_tabs {
height: 55px; /* changin height from 40px to 55px */
width: fit-content;
max-width: 100%;
position: relative;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.data_tab {
border: 1px solid #ddd;
display: inline-block;
width: fit-content;
/*height: 100%;*/
border-radius: 5px 5px 0 0;
padding: 10px 10px;
background: #f1f3f6;
cursor: pointer;
position: relative;
z-index: 10;
margin-right: 4px;
/* float: left; */
font-weight: 600;
}
.data_tab * {
display: inline-block;
}
.data_tab.active_data_tab {
background: #fff;
border-bottom: 1px solid #fff;
}
.ui-sortable-placeholder {
display: inline-block;
height: 1px;
}
/* width */
.data_tab_tabs::-webkit-scrollbar {
height: 6px !important;
}
/* Track */
.data_tab_tabs::-webkit-scrollbar-track {
background: transparent !important;
}
/* Handle */
.data_tab_tabs::-webkit-scrollbar-thumb {
background: #ddd !important;
border-radius: 3px;
}
/* Handle on hover */
.data_tab_tabs::-webkit-scrollbar-thumb:hover {
background: #ccc !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="data_tab_container">
<div class="data_tab_tabs">
<div class="data_tab active_data_tab" data-tab="headers" data-level="1">Here is something</div>
<div class="data_tab" data-tab="body" data-level="1">Here is something else</div>
<div class="data_tab" data-tab="footers" data-level="1">Here is something else again</div>
</div>
</div>

I had to contain the element .data_tab_tabs within another div which I named .data_tab_scroll.
I had to do quite a few css changes to get this to work correctly without breaking the way the tabs looked normally or when sorting.
With these changes another issue occurred which was that the sortable placeholder width would only be 1px wide when the scroll bar was visible. To fix this I needed .data_tab_tabs to have width: fit-content and for .data_tab_scroll to have width: 100%;. There is a question related to this issue here
Snippets here still have the original issue, and so does Internet Explorer.
You can find a working example in my codepen

Related

How to add javascript onclick event listener to container div?

Add onclick event listener to container div.
I tried the following, and as you can see, the event does not seem to be registered. How can I add the listener to this div?
The div id I want is "engineersContainer."
document.getElementById("engineersContainer").addEventListener("click", function(e) {
console.log("It was clicked");
alert("It was clicked");
});
.barContainer {
margin: 2px;
border: 2px solid black;
border-radius: 20px;
width: 200px;
//width:-moz-fit-content;
//width: fit-content;
padding: 5px;
overflow: hidden;
position: relative;
background: #34e8eb;
z-index: -1;
}
.containerHeader:before {
content:"";
background: skyblue;
position: absolute;
inset: 0;
z-index: -1;
height:45px
}
<div id="engineersContainer" class="barContainer">
<div id="engineerList" class="containerHeader" style="font-size:1.5em; text-align:center">Current Engineer </div>
<div> Engineer's Name</div>
<div id="clickText" style="padding-bottom: 10px; font-size:0.75em; text-align:center "> (Click to See All Permits) </div>
</div>
Remove the -1 z-index, otherwise it will be under the rest of the page
Add the event listener in the page load event
See second example for a workaround
window.addEventListener("load", function() {
document.getElementById("engineersContainer")
.addEventListener("click", function(e) {
console.log("It was clicked");
});
});
.barContainer {
margin: 2px;
border: 2px solid black;
border-radius: 20px;
width: 200px;
//width:-moz-fit-content;
//width: fit-content;
padding: 5px;
overflow: hidden;
position: relative;
background: #34e8eb;
/* z-index: -1 */
}
.containerHeader:before {
content: "";
background: skyblue;
position: absolute;
inset: 0;
z-index: -1;
height: 45px
}
.containerHeader {
font-size: 1.5em;
text-align: center
}
#clickText {
padding-bottom: 10px;
font-size: 0.75em;
text-align: center
}
<div id="engineersContainer" class="barContainer">
<div id="engineerList" class="containerHeader">Current Engineer </div>
<div> Engineer's Name</div>
<div id="clickText"> (Click to See All Permits) </div>
</div>
Otherwise add another div on top of it
window.addEventListener("load", function() {
document.getElementById("engineersContainerClick").addEventListener("click", function(e) {
console.log("It was clicked");
});
});
.barContainer {
margin: 2px;
border: 2px solid black;
border-radius: 20px;
width: 200px;
//width:-moz-fit-content;
//width: fit-content;
padding: 5px;
overflow: hidden;
position: relative;
background: #34e8eb;
z-index: -1
}
#engineersContainerClick {
margin: 2px;
border-radius: 20px;
width: 200px;
height:70px;
padding: 5px;
border:none;
overflow: hidden;
position: absolute;top:0;
background-color: transparent;
z-index:999;
}
.containerHeader:before {
content: "";
background: skyblue;
position: absolute;
inset: 0;
z-index: -1;
height: 45px
}
.containerHeader {
font-size: 1.5em;
text-align: center
}
#clickText {
padding-bottom: 10px;
font-size: 0.75em;
text-align: center
}
<div id="engineersContainer" class="barContainer">
<div id="engineerList" class="containerHeader">Current Engineer </div>
<div> Engineer's Name</div>
<div id="clickText"> (Click to See All Permits) </div>
</div>
<div id="engineersContainerClick" class="barContainer">
You need to remove the z-index: -1 in your CSS.
Any user clicks are not making contact with the element, but with the document above the element.
Working Example:
document.getElementById("engineersContainer").addEventListener("click", function(e) {
console.log("It was clicked");
alert("It was clicked");
});
.barContainer {
margin: 2px;
border: 2px solid black;
border-radius: 20px;
width: 200px;
/* width:-moz-fit-content; */
/* width: fit-content; */
padding: 5px;
overflow: hidden;
position: relative;
background: #34e8eb;
}
.containerHeader:before {
content:"";
background: skyblue;
position: absolute;
inset: 0;
z-index: -1;
height:45px
}
<div id="engineersContainer" class="barContainer">
<div id="engineerList" class="containerHeader" style="font-size:1.5em; text-align:center">Current Engineer </div>
<div> Engineer's Name</div>
<div id="clickText" style="padding-bottom: 10px; font-size:0.75em; text-align:center "> (Click to See All Permits) </div>
</div>
document.getElementById("engineersContainer").onclick=function(){
console.log("your event");
}
.barContainer {
margin: 2px;
border: 2px solid black;
border-radius: 20px;
width: 200px;
//width:-moz-fit-content;
//width: fit-content;
padding: 5px;
overflow: hidden;
position: relative;
background: #34e8eb;
}
.containerHeader:before {
content:"";
background: skyblue;
position: absolute;
inset: 0;
z-index: -1;
height:45px
}
<body>
<div id="engineersContainer" class="barContainer">
<div id="engineerList" class="containerHeader" style="font-size:1.5em; text-align:center">Current Engineer </div>
<div> Engineer's Name</div>
<div id="clickText" style="padding-bottom: 10px; font-size:0.75em; text-align:center "> (Click to See All Permits) </div>
</div>
</body>
ng-js -->
document.getElementById("engineersContainer").onclick=function(){
console.log("your event");
}
<div id="engineersContainer"> Here is the Engineers Container
</div>
I would use an anonymous function for this. You must call the script after your div has been created, as Javascript is read top to bottom and will not have a reference if it is run before the div has been placed.
Beware that if you have a listener on the container div, it will impact your ability to introduce any clickable options within the divs child elements such as buttons later on. Could this cause you problems in the future? If so rethink the design possibly to save you some trouble later. Also, the negative Z index needs to be removed as it is being drawn beneath the layer that Javascript detects the clicks. Sorry for the edits I'm new to StackO.

How to stop resizing div element when it reaches the specific width?

I tried to make a site with a resizable sidebar using jquery-resizable.js. What I want to do is making stop resizing once it reaches the specific width. However, it keeps moving even though it is already over the min-width value. I found the ResizeObserver to detect the changing width values and tried to change the div element's CSS values like resize:none; but it didn't work.
How could I stop resizing once it reaches a certain width value?
Here are my codes.
$(".panel-left").resizable({
handleSelector: ".splitter",
resizeHeight: false,
resizeHeightFrom:'center',
});
var ro = new ResizeObserver(entries => {
for (let entry of entries) {
const cr = entry.contentRect;
console.log('Element:', entry.target);
console.log(`Element size: ${cr.width}px x ${cr.height}px`);
console.log(`Element padding: ${cr.top}px ; ${cr.left}px`);
if (cr.width <= 330) {
console.log("its too small");
cr.css('resize', 'none');
}
}
});
ro.observe(document.querySelector('.panel-right'));
.panel-container {
display: flex;
flex-direction: row;
border: 1px solid silver;
overflow: hidden;
}
.panel-left {
flex: 0 0 auto;
padding: 10px;
width: 900px;
/* min-height: 100%; */
min-width: 650px;
white-space: nowrap;
background: #8E44AD;
color: white;
}
.panel-right {
flex: 1 0 auto;
padding: 10px;
width: 300px;
/* min-height: 100%; */
min-width: 350px;
background: #34495E;
color: #fff;
overflow-x: hidden;
}
.splitter {
flex: 0 0 auto;
width: 8px;
background: url(images/vsizegrip.png) center center no-repeat #ccc;
min-height: 100%;
cursor: col-resize;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://www.jqueryscript.net/demo/jQuery-Plugin-To-Generate-Resizable-DOM-Elements-Resizable/src/jquery-resizable.js"></script>
<div class="panel-container el" style="height:100%;">
<div class="panel-left resizable">
left panel
</div>
<div class="splitter">
</div>
<div class="panel-right" id="panelRight">
right panel
</div>
</div>
What you try do do is possible with max-width like #JHeth mentioned.
You can set the min-width to set the minimum width of your div and max-width to stop on the pixel size you want.
.panel-left {
min-width: 50px;
max-width: 200px;
width: 50%;
}
See the example below:
$(".panel-left").resizable({
handleSelector: ".splitter",
resizeHeight: false,
resizeHeightFrom:'center',
});
.panel-container {
display: flex;
flex-direction: row;
border: 1px solid silver;
overflow: hidden;
width: 100%;
}
.panel-left {
flex: 0 0 auto;
padding: 10px;
min-height: 100vh;
min-width: 50px;
max-width: 200px;
white-space: nowrap;
background: #8E44AD;
color: white;
width: 50%;
}
.panel-right {
flex: 1 0 auto;
padding: 10px;
min-height: 100vh;
background: #34495E;
color: #fff;
overflow-x: hidden;
}
.splitter {
flex: 0 0 auto;
width: 8px;
background: url(images/vsizegrip.png) center center no-repeat #ccc;
min-height: 100%;
cursor: col-resize;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://www.jqueryscript.net/demo/jQuery-Plugin-To-Generate-Resizable-DOM-Elements-Resizable/src/jquery-resizable.js"></script>
<div class="panel-container el" style="height:100%;">
<div class="panel-left resizable">
left panel
</div>
<div class="splitter">
</div>
<div class="panel-right" id="panelRight">
right panel
</div>
</div>

Add old value as "ghost" thumb to <input type="range"> Slider

I've styled a regular range slider using an example from w3schools. My goal is to send out a new value command to an external MQTT-based smarthome thing and show the old value as some kind of ghost-thumb first:
After the smarthome system confirms the new value, the bubble will be removed - but that's not my problem at this point. I would like to place the ghost between the background of the slider and the real-value-thumb, currently it looks like this:
Here you can see the result on JSFiddle, here's the code:
$('#slider_1').data('last-mqtt-value', 0.5);
$('#slider_1').on('input', function() {
// Show ghost slider
$('#slider_1_companion').css('left', 'calc('+ $(this).data('last-mqtt-value') / $(this).attr('max') +'* (100% - 20px))');
$('#slider_1_companion').css('display', 'block');
});
$('#slider_1').on('change', function() {
console.log( $(this).data('last-mqtt-value'), $(this).val() );
// Simulate new input value incoming
///*
setTimeout(() => {
$(this).data('last-mqtt-value', $(this).val());
$('#slider_1_companion').css('display', 'none');
},5000);
// */
});
.slider {
-webkit-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #ccc;
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #6c757d;
cursor: pointer;
z-index: 5;
}
.slider::-moz-range-thumb {
width: 20px;
height: 20px;
border-radius: 50%;
background: #6c757d;
cursor: pointer;
z-index: 5;
}
/*https://stackoverflow.com/a/46318225/1997890*/
.slider_wrapper {
position: relative;
width: 150px;
}
.slider_companion {
background-color: #ccc;
border-radius: 50%;
width: 20px;
height: 20px;
position: absolute;
top: calc(100% - 19px); /* for some reason this is not 20px (height of thumb) */
/* left: calc( PERCENTAGE * (100% - 20px)); /* add this line dynamically via jQuery */
display: none;
pointer-events: none; /*click-through*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slider_1_wrapper" class="slider_wrapper">
<div id="slider_1_companion" class="slider_companion"></div>
<input type="range" id="slider_1" class="slider" min="0" max="1.0" step="any">
</div>
I would consider a box-shadow for the slider that you can adjust with CSS variable and no need for extra element and you will have the expected result.
Here is an idea:
$('#slider_1').data('last-mqtt-value', 0.5);
$('#slider_1').on('input', function() {
document.getElementById('slider_1_wrapper').style.setProperty("--c",
($(this).data('last-mqtt-value') - $(this).val() )*130 + 'px');
/*130 = 150 - 20 = width of wrapper - width of thumb*/
});
$('#slider_1').on('change', function() {
console.log( $(this).data('last-mqtt-value'), $(this).val() );
// Simulate new input value incoming
///*
setTimeout(() => {
$(this).data('last-mqtt-value', $(this).val());
document.getElementById('slider_1_wrapper').style.setProperty("--c",0);
},5000);
// */
});
.slider {
-webkit-appearance: none;
width: 100%;
height: 10px;
border-radius: 5px;
background: #ccc;
outline: none;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #6c757d;
cursor: pointer;
z-index: 5;
box-shadow:var(--c,0) 0 0 red;
}
.slider::-moz-range-thumb {
width: 20px;
height: 20px;
border-radius: 50%;
background: #6c757d;
cursor: pointer;
z-index: 5;
box-shadow:var(--c,0) 0 0 red;
}
.slider_wrapper {
width: 150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slider_1_wrapper" class="slider_wrapper">
<input type="range" id="slider_1" class="slider" min="0" max="1.0" step="any">
</div>

jQuery Sortable - Keep empty space on item remove from list

I am trying to make a board where users can move sticky notes here and there which contain data.
I am utilizing the sortable jQuery library at the moment. It is working as it is designed to, but I want to modify the functionality a little. When I remove an item from the list, I want an empty space to be left in its place. For example, if I am removing the first item from the list, the rest of the items shouldn't be moved up and take the empty space.
Similarly, when I have only one item in a list and I remove it, I cannot add anything back to that list since the list goes away. I want to stop that from happening as well.
Here's the snippet (click to open).
$(document).ready(function() {
$('.sort-me-alpha').sortable({
connectWith: '.sort-me-gamma',
receive: function (event, ui) {
if ($(ui.item).hasClass('special')) {
ui.sender.sortable('cancel');
}
}
});
$('.sort-me-beta').sortable({
connectWith: '.sort-me-gamma',
receive: function (event, ui) {
if (!$(ui.item).hasClass('special')) {
ui.sender.sortable('cancel');
}
}
});
$('.sort-me-gamma').sortable({
appendTo: document.body,
items: '.sticky',
placeholder: "testclass",
connectWith: '.sort-me-alpha, .sort-me-beta',
receive: function (event, ui) {
//console.log(event, ui.item);
//ui.item.remove(); // remove original item
}
});
});
.sort-me {
/* background-color: #3498db; */
min-height: 30px;
margin: 10px;
padding: 10px;
width: auto;
vertical-align: top;
display: inline-block;
}
.sort-me-alpha {
/* background-color: #3498db; */
min-height: 30px;
margin: 10px;
padding: 10px;
width: auto;
vertical-align: top;
display: inline-block;
}
.sort-me-gamma {
/* background-color: #3498db; */
min-height: 30px;
margin: 10px;
padding: 10px;
width: auto;
vertical-align: top;
display: inline-block;
}
.sort-me-beta {
/* background-color: #3498db; */
min-height: 30px;
margin: 10px;
padding: 10px;
width: fixed;
vertical-align: top;
display: inline-block;
}
.testclass {
background-color: gray;
border: 2px solid gray;
width: 100%;
height: 100%;
}
.sticky {
/* position: absolute; */
right: 0;
z-index: 150;
/* transform: rotate(5deg); */
width: 200px;
min-height: 150px;
margin: 10px 10px 10px;
padding: 10px;
/* font-family: "Comic Sans MS", "Comic Sans", "Chalkboard SE", "Comic Neue", cursive; */
font-size: 14px;
color: #000;
background: rgba(255, 255, 51, 0.8);
box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.3);
}
.sticky:before,
.sticky:after {
content: "";
display: block;
position: absolute;
width: 16px;
height: 16px;
top: 0;
right: 0;
}
.sticky:before {
border-top: solid 8px #fff;
border-right: solid 8px #fff;
border-left: solid 8px transparent;
border-bottom: solid 8px transparent;
}
.sticky:after {
border-bottom: solid 8px #dddd33;
border-left: solid 8px #dddd33;
border-right: solid 8px transparent;
border-top: solid 8px transparent;
}
.ui-helper {
width: 100% !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<div class="container">
<div class="sort-me-alpha">
<div class="sticky">
<b>Card 1</b> Put any text in here.
</div>
<div class="sticky">
<b>Card 2</b> Put any text in here.
</div>
</div>
<div class="sort-me-beta">
<div class="sticky">
<b>Card n</b> Put any text in here.
</div>
</div>
<div class="sort-me-gamma">
<div class="sticky">
<b>Card 3</b> Put any text in here.
</div>
<div class="sticky">
<b>Card 4</b> Put any text in here.
</div>
</div>
</div>
When I move Card N to any other list, I cannot bring it back since the list ceases to exist.
Also if I were to move Card 3 to any other list, Card 4 comes up and takes its place, I know this is the default behavior, but can I override it?
One question per question, please. I'll answer the first one.
You should use:
$("#sticky-id").css('visibility','hidden');
The property visibility:hidden keeps the space as it is.
To remove an element, just use remove() instead of touching visibility.
If you want to add an element inside the list use:
remove: function(event, ui) {
console.log(event);
console.log('removed');
$('.sort-me-gamma').prepend('<div class="sticky">' + '<b> I am a dummy card </b>' + '</div>' );
}
And if you want a generic function to do this, you'll need:
.insertAfter('#list :nth-child(<give childnumber here>)')
And to get childnumber use an on click event and set an attribute which contains the ID in each card when creating HTML code, for example id=card-number-[putherevalue]

how to make transition effects(slide) in autocomplete

autocomplete working fine but i need a transition effect(slide down) in suggested menu,
I referred from this sites http://tutsforweb.blogspot.in/2012/05/auto-complete-text-box-with-php-jquery.html
and i tried
$(document).ready(function() {
$("#tag").autocomplete("autocomplete.php", {
selectFirst: true
});
});
.ac_results {
background-color: white;
border: 1px solid #5c5c5c;
left: 174.5px !important;
overflow: hidden;
padding: 0;
width: 247px !important;
z-index: 99999;
}
.ac_results ul {
width: 100%;
list-style-position: outside;
list-style: none;
padding: 0;
margin: 0;
}
.ac_results li {
margin: 0px;
padding: 2px 5px;
cursor: default;
display: block;
font-family: "armataregular";
font-size: 12px;
line-height: 16px;
overflow: hidden;
}
.ac_loading {
background: white url('indicator.gif') right center no-repeat;
}
.ac_odd {
background-color: #eee;
}
.ac_over {
background-color: #ccc;
color: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="listone">
<input type="text" placeholder="Enter Keyword" id="tag">
</div>
I added transition property on id="tag" and .ac_results its not working,
please suggest any idea.,
Transitions work by listening to a property and will "animate" when that property changes. So in your case you would need to add a transition to #ac_results. Set the #ac_results height to 0, and when it finds results change the height that element and it should slide down
transition: height 0.5s ease-in-out;
height: 0;
Here is a quick example of it (note that it doesn't do any auto complete, just it shows when input is detected)
http://jsfiddle.net/schwqa7k/1/

Categories

Resources