I have an element on my page that I want to make draggable.
On the click event I add the class ‘active’ this just expands my div and the image inside it.
So initially my div looks like…
<div class="work-showcase">
on click it becomes…
<div class="work-showcase active">
I want to say if the div has class active, perform X function, else perform Y.
$(body).click(function(){
if($('.work-showcase').hasClass('active')){
var bleft = 4900 ;
var bright = $(window).width() - 200;
$('.active > ul li').draggable({
axis: "x",
revert: false,
stop: function(event, ui) {
if(ui.position.left < -bleft)
{
$(this).animate({"left": "0px"}, 600);
}
if(ui.position.left > bright)
{
$(this).animate({"left": "0px"}, 600);
}
}
});
} else {
var sleft = 1846 ;
var sright = $(window).width() - 200;
$('.work-showcase > ul li').draggable({
axis: "x",
revert: false,
stop: function(event, ui) {
if(ui.position.left < -sleft)
{
$(this).animate({"left": "0px"}, 600);
}
if(ui.position.left > sright)
{
$(this).animate({"left": "0px"}, 600);
}
}
});
}
});
My If statement doesnt seem to work…
Try this instead of what you currently have (let me know if there is a problem)