Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:10:27+00:00 2026-06-18T00:10:27+00:00

I have an element on my page that I want to make draggable. On

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:10:28+00:00Added an answer on June 18, 2026 at 12:10 am

    Try this instead of what you currently have (let me know if there is a problem)

    $('body').click(function () {
        var drag, left, right;
    
        if ($('.work-showcase').hasClass('active') === true) {
            drag = '.active > ul li';
            left = -4900;
            right = $(window).width() - 200;
        } else {
            drag = '.work-showcase > ul li';
            left = -1846;
            right = $(window).width() - 200;
        }
    
        $(drag).draggable({
            axis: 'x',
            revert: false,
            stop: function (event, ui) {
                if (ui.position.left < left) {
                    $(this).animate({'left': '0px'}, 600);
                } else if (ui.position.left > right) {
                    $(this).animate({'left': '0px'}, 600);
                }
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an <li> element on the page that I want to look a
Using the jquery metadata plugin, I have an element on my page that looks
If I have an element on a web page that I expect to be
If have an element that maybe disabled on a page, and would like to
I have a piece of jQuery code that fills an element on the page
On my page http://bit.ly/KseVxs I have a floating element that stays at one place
I want to make my DIV element to be able to click and go
I want to make a call to my action and have that action either
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input
I have an html page. On that page I want to open popup window.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.