Menu
Baran Kahyaoglu Dev Blog
Baran Kahyaoglu Dev Blog

Metro Style Application & Horizontal Scrolling

Posted on 30/04/201229/07/2015 by brnkhy

So I’ve been playing with Windows 8 and WinRT for a while now, had a little problem the other day and thought it would worth to post the workaround I found.

If you ever saw a metro style application demonstration, you probably noticed that applications using metro design style prefers horizontal scrolling over vertical for big bodies. Obviously they thought that horizontal scrolling feel much more natural on a touch device ( which I actually agree ).

The problem is, it’s flat out horrible for Keyboard&Mouse devices ( aka. 99.9% of Windows users ). And for some reason, they didn’t implemented a function to bind mouse wheel scroll to horizontal scroll by default. Weird.

But well it’s not hard anyway, you just have to remember that you’re pretty much coding for IE. Which means you can use some IE functions that other browsers don’t support ( and that seems why they’re kinda forgotten I guess? )

So this is what you got to do;

    document.documentElement.onmousewheel = function (event) {
        $(‘#contenthost’).scrollLeft($(‘#contenthost’).scrollLeft() – event.wheelDelta);
    };

Obviously ContentHost should be the element with scrollbar. And you should be careful using this because you obviously don’t want it in snapped view so

    updateLayout: function (element, viewState) {
        if (viewState != appViewState.snapped) {
            document.documentElement.onmousewheel = function (event) { $(‘#contenthost’).scrollLeft($(‘#contenthost’).scrollLeft() – event.wheelDelta); };
        }
    }
So that’s it, now your mouse wheel should scroll the page horizontally!
I hope you find it useful., see you in another post.
Share on Social Media
twitter facebook linkedin reddit email

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

5 thoughts on “Metro Style Application & Horizontal Scrolling”

  1. hady says:
    31/05/2012 at 9:16 am

    I tried it and this is just working in ie10 it is not working in metro style apps.

    Reply
  2. Don says:
    04/06/2012 at 11:31 pm

    For anyone not able to get this to work, change #contenthost to .win-horizontal and you should be good to go.

    Reply
  3. Baran says:
    06/06/2012 at 12:11 pm

    Huh that's interesting. What Don suggested might work though. The thing is I don't really use Metro tags&objects. For now I just delete everything and go pure Html&Javascript so don't know much about classes or elements like .win-horizontal etc.

    Also, thanks Don!

    Reply
  4. Shamir says:
    07/08/2012 at 7:05 am

    I'm using the Grid template and what I am trying to do is find out the scrollLeft value when I click a listview item and use it to position the page with the listview to the value it was before the click when I get back to the page again.
    I was able to get the value of scrollLeft but can't seem to set it.
    listViewhost = listView.querySelector(".win-horizontal");
    position = listViewhost.scrollLeft;

    and then
    listViewhost.scrollLeft = position;
    and it doesn't work, can you help please?

    Reply
  5. Baran says:
    31/08/2012 at 4:34 pm

    I'm really sorry for the laaate reply, pretty busy these days.

    I pretty much stopped working on W8 after this post and forgot almost everything 🙁 I believe you set scrollLeft using something like this though;

    listViewhost.scrollLeft(position);

    if I recall correctly ( might be totally wrong ), it's not a variable, it's a function.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Subscribe to Blog via Email

Follow me on Twitter!

My Tweets

Categories

  • Desktop Development (26)
  • Game Development (39)
  • Mapbox Unity SDK (4)
  • Uncategorized (8)
  • Unity3D (21)
  • Web Development (6)
  • WinRT Development (1)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Baran Kahyaoglu Dev Blog | Powered by WordPress & Superb Themes