[ 6 posts ]

Jean-Albert

  • Username: ltrlngp
  • Joined: Mon Nov 21, 2011 4:16 am
  • Posts: 4
  • Offline
  • Profile

What is the best way to update a scrollview size ?

Post Posted: Mon Nov 21, 2011 4:24 am
+0-
Hello,

I have a div with a size that can vary (it is a shopping cart) and I render it using a scrollable view.

Each time an object is added to or remove from the cart, I create a new ScrollView object which I render to have my scrollbale view rendered with the right size, able to show the whole cart.

Is there a better way to update the current scrollview object to achieve this goal ?
How you guys are you doing for such a purpose ?

Thanks in advance for all your tips.

Lionel

Code:
        [...]
   function createScrollView2 () {
      var scrollview2 = new Y.ScrollView({
          srcNode:"#scrollable2",
          height:"429px"
      });
      scrollview2.render();
   }
        [...]
   function completeAddToCart (id, o, args)
   {
      eval('var obj = ' + o.responseText);
      addElementToCart (obj);
      createScrollView2();
   }
        [...]

Jean-Albert

  • Username: ltrlngp
  • Joined: Mon Nov 21, 2011 4:16 am
  • Posts: 4
  • Offline
  • Profile

Re: What is the best way to update a scrollview size ?

Post Posted: Sun Nov 27, 2011 12:46 pm
+0-
Hello,

Perhaps my way is the best way :)
But I still have a doubt about it, so I "up" this topic :)

Thank you for reading

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 617
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: What is the best way to update a scrollview size ?

Post Posted: Tue Nov 29, 2011 5:51 am
+0-
You can change the size of any widget, including ScrollView, by setting the "width" or "height" attribute.
Code:
scrollview.set('height', 400);

Creating multiple widgets just for changing their size can become slow very quickly.

Jean-Albert

  • Username: ltrlngp
  • Joined: Mon Nov 21, 2011 4:16 am
  • Posts: 4
  • Offline
  • Profile

Re: What is the best way to update a scrollview size ?

Post Posted: Tue Nov 29, 2011 6:14 am
+0-
¡Gracias Juan!

Well I perhaps used the wrong words to explain what I am trying to do.

The scrollable viewport stays the same size. But the content scrolled (the one that does not fit in the viewport) is refreshed and its size changes.

When the size of this content changes (I add a product to the shopping cart for example) then I can view the content that was added by scrolling down using the elastic bouncing behavior of the scrollview but if I release the click (or the touch), this new content is not visible and I cannot scroll down to it.
It seems that the scrollview object is not aware that the scrolled content has a new height.

Thanks for reading.

Lionel

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 617
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile
Tags:

Re: What is the best way to update a scrollview size ?

Post Posted: Tue Nov 29, 2011 8:17 am
+0-
I made a jsfiddle to try this out. http://jsfiddle.net/juandopazo/wHSFu/1/

If I understood correctly how ScrollView works, you just need to call scrollview.syncUI() after adding content to it.

Jean-Albert

  • Username: ltrlngp
  • Joined: Mon Nov 21, 2011 4:16 am
  • Posts: 4
  • Offline
  • Profile

Re: What is the best way to update a scrollview size ?

Post Posted: Wed Nov 30, 2011 2:48 am
+0-
Juan ! You made my day !

Thank you so much for the answer and for the example.

Lionel
  [ 6 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum