1

I am using the swipe event (and http://api.jqueryui.com/slide-effect/) to slide out content. This works fine. However, I need to slide in the next('div') as the previous sibling slides out. I have tried next(), nextAll(), closest() but none seem to do what I require.

Here is the function

function swipeleftHandler(event){  
    $(this).toggle( "slide" );// div slides out to left

    // need to slide in next one here

}

The HTML looks like this

<div id="content2" class="content tabcontent active" data-content="1">
<div id="orders_today" class="datagroup datagroup0"></div>
<div id="orders_last_30_days" class="datagroup datagroup1 hide">
</div>

The swipe event is called like this

$(document.body).on('swipeleft', '.datagroup' ,swipeleftHandler);

The swipe event is being captured correctly, and the first div is sliding off to the left as required. I need the next div to side in. There may be multiple elements in the container with the same class (and unknown ID's), so that's why I tried using next()

4
  • 1
    Could you please show your HTML markup. Commented Jul 9, 2013 at 11:55
  • post you related HTML codes too Commented Jul 9, 2013 at 11:55
  • I have added more detail to the question Commented Jul 9, 2013 at 12:36
  • can you provide fiddle if possible? Commented Jul 9, 2013 at 12:40

2 Answers 2

1

Cache the next before hiding this:

$("body").on("click", "div", function(){
   $next = $(this).next();
   $(this).toggle("slide");
   $next.toggle("slide");
});

jsFiddle

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your input. My HTML was fine, just not typed into stackoverflow properly. Thanks for the fiddle, it works. there, but still not working on my app.
Have checked your updated fiddle. Thanks for that. Unfortunately I cannot use the ID as a selector in CSS as the selector will not be available (will be unknown) at page load and will be added dynamically using jQuery
The CSS doesn't matter, I can update it if it confusing :) The key is to store the next element before hiding the current one (you can copy the content of my handler to your handler and it will work, no other change is required in your code)
I've updated the fiddle and removed all IDs and change hide/show to toggle
Thanks for your solution, which incidently is similar to the one I have come up with myself.
0

The solution I found to this is to

  1. Remove the hide class
  2. set the height container (#content2) dynamically as a proportion on the viewport height.
  3. #content2{overflow:hidden}

then in my swiftlefthandler function, I used the following

$(this).toggle( "slide" );
$(this).next().toggle( "slide" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.