I'm a novice in javascript and jquery. I have a code for bars to slide and which works fine on jsfiddle; however, when I try to run the as an HTML file, it does not work. I do not know what I'm missing out here or what needs to be done to make this code work. Kindly let me know what library files I will have to include in the code for the bars to slide in HTML.
The link for my code on jsfiddle is: http://jsfiddle.net/sgx9L8sx/
Any help will be appreciated.
Thanks in advance.
`.box {
width:40px;
height:10px;
background:blue;
}
.box1 {
width:25px;
height:10px;
position:relative;
top:40px;
left:40px;
background:black;
}
.result{
position:fixed;
top:20px;
}
.result1{
position:fixed;
top:70px;
}
<script>
$(".box").draggable({
axis: "x",
drag: function(event, ui) {
var y2 = ui.position.top;
var x2 = ui.position.left;
if (reverting){
event.preventDefault();
event.stopImmediatePropagation();
} else if (x2 > 100) {
reverting = true;
revertDrag($('.box'));
}
else if (x2<0) {
}
}
});
function revertDrag(element){
element.draggable('disable');
element.animate({
top: 0,
}, {
duration: 500,
complete: function() {
reverting = true;
element.draggable('enable');
}
})
}
$(".box1").draggable({
axis: "x",
drag: function(event, ui) {
var y3 = ui.position.top;
var x3 = ui.position.left;
if (reverting1){
event.preventDefault();
event.stopImmediatePropagation();
} else if (x3 > 200) {
reverting1 = true;
revertDrag1($('.box1'));
alert("this is incorrect");
}
else if (x3<40) {
alert("Wrong submission");
revertDrag2($('.box1'));
}
}
});
function revertDrag1(element){
element.draggable('disable');
element.animate({
top:40,
}, {
duration: 500,
complete: function() {
reverting1 = false;
element.draggable('enable');
}
})
}
function revertDrag2(element){
element.draggable('disable');
element.animate({
top:40,
left:70,
}, {
duration: 500,
complete: function() {
reverting1 = true;
element.draggable('enable');
}
})
}
</script>
<body>
<div class="box">
</div>
<div class="result">
</div>
<div class="box1">
<div class="result1">
</div>
</div>
</body>