JQuery UI.widgets resets the scroll positions of children when they are hidden.

I am using jQuery UI with my latest project. Unfortunately, I came across a large wall due to some really clumsy behavior displayed by jQuery UI widgets when they contain elements with scroll bars for overflowing.

Check out this demo.

  • Scroll down in one of the .scroll-container items
  • Click accordion heading
  • Click on the old title - note that the item was automatically scrolled up.

In any case, to prevent this from happening? It is screwed up with my main plugin which uses jQuery scroll. I don’t understand what to do here!

Perhaps this is a mistake worth mentioning in the jQuery UI dev forums ...

Edit

So far, the error has been confirmed. in...

  • Chrome - 8.0.552.231 on OSX 10.6.5
  • Safari - 5.0.3 on OSX 10.6.5 (makes sense)
  • FF - 3.6.12 on OSX 10.6.5

And not present in ...

  • FF - 3.6.12 on OSX 10.6.5
+4
source share
2 answers

According to the jQuery user interface that answered my request:

This is how browsers work, as soon as you hide an element, it loses its scroll position.

0
source

I had the same problem. The workaround I came up with is to set the identifier of the ui object after creation. Then I keep the scrollTop () position before hiding the object. And when I show the object again, I just set scrollTop () to the stored value.

 // Set the id of the object if you have multiple objects with the same class if ($("#divScroll").length == 0) { // If the object does not exist with an id $(".ui-jqgrid-bdiv").each(function () { // Select each object via class strID = $(this).attr("id"); // If the current object (selected via class) does not have an id, set id if (strID == undefined || strID == false) { $(this).attr("id", "divScroll"); } }); } // Save the scroll position before hide() intScrollTop = $("#divScroll").scrollTop(); $("#divScroll").hide(); // Set the scroll position to the saved value after show() $("#divScroll").show(); $("#divScroll").scrollTop(intScrollTop); 
+1
source

Source: https://habr.com/ru/post/1332974/


All Articles