overflow:hidden doesn't work on .animate() to the left, but works to the right?

Ricardo Melo

I have been reading around and couldn't figure out what is wrong with this animation.

I am trying to do a transition and slide the old content of the page to the side before I load the new content.

I am using the current code:

$('#clickbutton').click(function(e) {
    $('#loader').css('overflow','hidden');
    $('#loader').animate({left: "100vw"},600, function(){
        $('#loader').empty();
        $('#loader').css("left", "0vw");
        $('#loader').css('overflow','auto');
        $('#loader').load('../viewers/docentes/docentes.lista.php');
    });
  });

the loader is a container, child of body, its position is relative, body has no css changes apart from default.

The strange thing is, if i change {left: "100vw"} to {left: "-100vw"} the container animation shifts direction to the right instead, and the scrollbar does not appear.

Why is it not working as well going to the left?

Louys Patrice Bessette

You can't animate the left CSS propertie of a non-positioned element.

But you can achieve what you want using the margin-left propertie.
A negative margin-left will push the element to the left.

$('#clickbutton').click(function(e) {
    $('#loader').css('overflow','hidden');
    $('#loader').animate({"margin-left": "-100vw"},600, function(){
        $('#loader').empty();
        $('#loader').css("margin-left", "0vw");
        $('#loader').css('overflow','auto');
        //$('#loader').load('../viewers/docentes/docentes.lista.php');
        $('#loader').html("New text is here!");
    });
  });
#loader{
    border:1px solid black;
    width:400px;
    height:400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="button" id="clickbutton"value="Click me">
<br>
<br>
<div id="loader">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porta lorem quis gravida tempus. Fusce scelerisque vehicula ornare. Phasellus dapibus cursus augue, et accumsan lorem ultricies et. Aenean suscipit placerat nisl, congue elementum ligula porta ut. Duis lacinia lacinia augue, eu mattis lacus blandit eget. Quisque accumsan ante vitae porta interdum. Aliquam maximus ut est sed luctus. Sed sed orci in urna feugiat mollis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla non neque arcu. Nam cursus ultrices leo non egestas. Vivamus id nisi auctor, tempus urna eu, interdum risus. Nulla urna purus, porta et scelerisque at, pellentesque a erat.
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

overflow: hidden doesn't work on a pseudo element

From Dev

overflow-x: hidden doesn't work, instead adds padding on the right when scrolled

From Dev

Synergy doesn't work correctly if I switch client/server role (left of works, right of does not)

From Dev

Overflow hidden doesn't work on firefox, but does work in IE and chrome

From Dev

box shadow to left and right doesn't work

From Dev

UIView doesn't animate horizontally from right to left

From Dev

UIView doesn't animate horizontally from right to left

From Dev

Overflow hidden doesn't work despite having height set

From Dev

Chrome 55: position: fixed; in div overflow: hidden; doesn't work

From Dev

JS function named `animate` doesn't work in Chrome, but works in IE

From Java

CSS Transition doesn't work with top, bottom, left, right

From Dev

setMargins(left, top, right, bottom); Android doesn't work

From Dev

Left Ctrl Key doesn't work (but right one does)

From Dev

ScrollTop animate does not work if html, body is overflow-x: hidden

From Dev

Can't get "overflow: hidden" to work on image

From Dev

jquery .animate() doesn't work

From Dev

CSS display:table-cell, set height and overflow:hidden, doesn't work?

From Dev

Attaching an event listener for left or right click - onclick doesn't work for right click

From Dev

Animate border left to right

From Dev

float right doesn't work

From Dev

LEFT JOIN doesn't work

From Dev

Overflow: hidden not work

From Dev

ignoring text height using float left doesn't work but right does

From Dev

If I hold down the left or right mouse button, mouseenter doesn't work

From Dev

If I hold down the left or right mouse button, mouseenter doesn't work

From Dev

tmux / screen ctrl+arrow (left right) doesn't work on SSH

From Dev

ms word find/replace highlighted text, doesn't work on this mix of hebrew and english in right to left mode

From Dev

jquery animate doesn't work properly

From Dev

JQuery animate doesn't work on first click

Related Related

  1. 1

    overflow: hidden doesn't work on a pseudo element

  2. 2

    overflow-x: hidden doesn't work, instead adds padding on the right when scrolled

  3. 3

    Synergy doesn't work correctly if I switch client/server role (left of works, right of does not)

  4. 4

    Overflow hidden doesn't work on firefox, but does work in IE and chrome

  5. 5

    box shadow to left and right doesn't work

  6. 6

    UIView doesn't animate horizontally from right to left

  7. 7

    UIView doesn't animate horizontally from right to left

  8. 8

    Overflow hidden doesn't work despite having height set

  9. 9

    Chrome 55: position: fixed; in div overflow: hidden; doesn't work

  10. 10

    JS function named `animate` doesn't work in Chrome, but works in IE

  11. 11

    CSS Transition doesn't work with top, bottom, left, right

  12. 12

    setMargins(left, top, right, bottom); Android doesn't work

  13. 13

    Left Ctrl Key doesn't work (but right one does)

  14. 14

    ScrollTop animate does not work if html, body is overflow-x: hidden

  15. 15

    Can't get "overflow: hidden" to work on image

  16. 16

    jquery .animate() doesn't work

  17. 17

    CSS display:table-cell, set height and overflow:hidden, doesn't work?

  18. 18

    Attaching an event listener for left or right click - onclick doesn't work for right click

  19. 19

    Animate border left to right

  20. 20

    float right doesn't work

  21. 21

    LEFT JOIN doesn't work

  22. 22

    Overflow: hidden not work

  23. 23

    ignoring text height using float left doesn't work but right does

  24. 24

    If I hold down the left or right mouse button, mouseenter doesn't work

  25. 25

    If I hold down the left or right mouse button, mouseenter doesn't work

  26. 26

    tmux / screen ctrl+arrow (left right) doesn't work on SSH

  27. 27

    ms word find/replace highlighted text, doesn't work on this mix of hebrew and english in right to left mode

  28. 28

    jquery animate doesn't work properly

  29. 29

    JQuery animate doesn't work on first click

HotTag

Archive