views:

72

answers:

1

I have a 1page website that is driven by jquery scrollTo plugin which, I guess, doesn´t matter in my case. The problem seems to be the 1page design. If I click the tab, the entire design is messing up because the tab jumps to whatever it can find to focus on. That includes places that are outside of the current viewport area.
Actually I don´t want the tab to focus on anything except from my #contactForm div after you clicked into the first form field. The tab could focus on that but only if the hash "#contact" is within the viewport. Is there any way to realize something like that or does the tab/focus thing always mess up 1 page designs that are dealing with content outside of the viewport area?

Maybe some ideas can help me to understand that issue a little better

+1  A: 

Since I don't know what your HTML looks like, I borrowed the ScrollTo demo. You can try making a link that has focus inside the panel force the panel into view (demo):

Something like this:

$('#pane-target li a').bind('focusin', function() {
    $('#pane-target').scrollTo( $(this).closest('li'), 800, {queue: true} );
})

Updated demo to remove conflict between bind and click on the back button.


Update: Changed demo to work with HTML/Script from the link you provided. I had to modify it quite a bit so the links wouldn't conflict. Also, I moved the .selected class to the item instead of the link in the first panel only. Hopefully I added enough comments to make it all clear.

 $('a').bind('focusin click', function(e){

  // focusin occurs before click
  if (e.type == 'click') {

   var tar = $(this).attr('href');

   if ($(this).is('.panel')) {
    // clicked on a.panel; scroll to destination
    $('#wrapper').scrollTo(tar, 800);
    //reset and highlight the clicked link
    $('.item').removeClass('selected');
    $(tar).addClass('selected');
    //cancel the link default behavior
    return false;
   } else {
    // clicked on link (not '.panel'), return true in case it's an external link
    return true;
   }

  } else {
   // link was focused 
   var time, item = $(this).closest('.item');
    if (item.is('.selected')){
     // if item is already in view (position it immediately)
     time = 0;
    } else {
     // item is not in view, so smoothly scroll & update classes
     time = 800;
     $('.item').removeClass('selected');
     item.addClass('selected');
    }
   $('#wrapper').scrollTo(item, time);
  }

 });
fudgey
Hi Hardy, I've updated my answer and provided a demo... hopefully I chose the correct version. Oh and the demo on jsFiddle is a bit more "jerky" than the version I had locally.
fudgey
Hi Hardy, I can't help without seeing your HTML since it isn't the same as the original code - empty panels would work.
fudgey
Try this: http://jsfiddle.net/797Xj/5/... I removed all the extra `id="item"` since IDs should be unique. I had to comment out a couple of lines for the nivo slider so the demo would work.
fudgey
Almost there but not 100%. I have added 3 remarks to the script in jsfiddle. They start and end with #######. You will see them. First was about the related links, second one about to stop the nivo slider. That was missing and third is about the feeling that a complete part gets ignored. My live test was scrolling diaconally but it should not do that because the option "queue" is set to true and that makes it scroll horizonatally, then stop and then vertically instead of scrolling zig zag.
Hardy
Also with my added line "stop nivo", the nivo really stops but is not starting again. So I think that a whole part gets ignored. Can you follow?
Hardy
I had the time for scrollTo set after the que, that's why it wasn't working. All fixed now in this version: http://jsfiddle.net/797Xj/8/ As for the nivo, I think you have more than one `#slider` id, change these to classes, then use `$('#wrapper .slider').data('nivo:vars').stop = true;` to stop all sliders and `$('#wrapper .selected .slider').data('nivo:vars').stop = false;` to only start the one visible.
fudgey
Hi fudgey - your demo is working perfectly but if I paste the code, as it is in the demo, into my website it is not scrolling at all unless I add "#main-menu a, #meta-nav a," to where it says "if ($(this).is('.link'))" like so "if ($(this).is('#main-menu a, #meta-nav a, .link'))". I think this is strange because we both use the same html markup and the same css classes for styling and positioning. So why is it not scrolling at all if I paste in in but your demo is scrolling perfectly?
Hardy
@fudgey - Your help is much, much more than I have expected from this portal. Maybe I can make the real thing accessable for you by uploading it for inspection. But of course, I can not expect that you are willing to do that. So please let me know. Maybe you have another idea why I have to make those changes just to make it scroll within my invironment.
Hardy
I did add some CSS.. you might want to check that. Are you using Firefox + Firebug? It may be possible you have an error somewhere. Also, if you have the site live somewhere, I wouldn't mind looking at it.
fudgey
I uploaded for you. It is working with your last edit but I had to change to "if ($(this).is('#main-menu a, #meta-nav a, .link'))" as mentioned above. Otherwise it would not scroll. Maybe the real thing is telling you more. Use the tab key some times and you will see what happens. It is best visible in chrome because it is adding a better frame to the focused items. Here it is http://cozyphant-living.com/fiddle/fudgey
Hardy
Ok, try this: http://jsfiddle.net/TEHt6/ I had to add the `content-box-inner` div because while tabbing through the pages, Chrome focused on these divs. I got the demo working locally, but there were a lot of errors - some scripts weren't loaded and some other errors were popping up. So tell me if this update works for you.
fudgey
Hi fudgey (Part 1)- first of all.....it seems to work perfectly on my side but there is some irritation because I don´t know what the new script is actually doing to the site. The reason for the irritation is this. I have a "welcome screen" (as I call it) that appears in front of the page if the site is loaded. If you click a "go" button it disappears and the actual side is showing up. You can view here: http://cozyphant-living.com/fiddle/fudgey/default2.html The demo is running with the old script which means that you can open the panel by clicking on the go button.
Hardy
Hi fudgey (Part 2)- Once you paste your new script in, the go button does not work anymore, meaning the panel will stay closed, the site can not be reached. The code snippets for the welcome panel are also here: jsfiddle.net/HqKYAI mean, what could this be? What does your script have to do with the welcome panel. I can not see any relation and apart from that malfunction, your script works like a charme. Everything looks so cool now - apart from that malfunction welcome screen. Maybe you got an idea what it could be. I have to thank you soooooo veryyyyy much.
Hardy
@fudgey - STOP, STOP...read this first. I guess you can ignore the last 2 comments because I found out that I have to include the "welcome screen" script before the "scrollTo" script to make the site work. I guess there is no other thing to do that to accept the line up of the scripts. As far as I have seen - IT WORKS LIKE A CHARME. I will do some heavy testing now and let you know the final result shortly. I think I will use your regular mail address for that. See you, Cheers.
Hardy