3

The website I'm working on will not scroll until somewhere on a page is clicked with the mouse or 'tabbed' through with the tab key.

Is there a simple answer I am over looking?

EDIT- Okay here is a simple bit of javascript I need help with.

I put this bit at the end of the existing javascript file being called

 function setFocus() {
        document.getElementById("#realBody").focus() ;
 }

I put this bit(just the onload part) in the main php file

</head>
<body class="<?php print $classes; ?>" onload="setFocus()">
  <div id="realBody">

This isn't working, if this simple code is usable I'd love some pointers.

I am trying to draw focus to realBody

winchendonsprings
  • 471
  • 2
  • 7
  • 17

5 Answers5

4

Perhaps you are focusing on a text field or dropdown menu, and your input (scrolls) are tied to that one control? Are you explicitly calling Focus() on one of the controls on the page?

WEFX
  • 8,298
  • 8
  • 66
  • 102
  • I'm not sure. There is a lot going on on the page. Anyway to figure it out what element gets first focus with firebug? – winchendonsprings Jun 27 '11 at 19:47
  • I'm not sure about finding the element using firebug/fiddler, but [this post](http://stackoverflow.com/questions/512296/how-to-determine-which-control-on-form-has-focus) lists a few suggestions. – WEFX Jun 27 '11 at 20:02
  • Is there a way to do it with css? A way to force focus? The link you provided seems reasonable but it's above my level at the moment. – winchendonsprings Jun 27 '11 at 21:07
  • [This page](http://www.w3schools.com/css/sel_focus.asp) talks about adding a yellow outline to the web-control that has focus via CSS. – WEFX Jun 27 '11 at 21:48
  • I was just looking at that page before I checked back here. I also just edited the question with a little bit of code that maybe you can help out with. I am trying to draw focus to a section of the page rather than an input field if that matters. – winchendonsprings Jun 27 '11 at 23:18
3

remove the hash mark '#'.

Or if your using jQuery

 $(function() {
      $('#realBody').focus();
 });
Nathan Romano
  • 7,016
  • 3
  • 19
  • 18
  • removed th hash mark. Still not focused on load. I realize there are other factors, but is there anything I can try? Add a little more to the code? – winchendonsprings Jun 28 '11 at 06:02
0

WEFX is probably right, it sounds like you have a focus issue. Try adding the code from this article so it focuses on a text input or other field that won't steal the scroll wheel.

http://www.wombatnation.com/2008/07/setting-html-input-field-focus-on-load

As far as I know there isn't a good way to do it in CSS, but there is very little javascript involved here. It won't bite, I promise :)

Chriszuma
  • 4,464
  • 22
  • 19
0

Had a similar problem lately where the page would not scroll until I clicked. I was using the shadcn ui Select tag and I set the defaultOpen attribute to true.

<FormField control={form.control} name="role" render={({ field })=> (
    <FormItem className="col-span-3 md:col-span-4  w-full p-0 m-0">
        <FormControl>
            <Select disabled={!editingMode} onValueChange={(value: "mpesa" | "bank" | "paypal" )=> {
                field.onChange(value);
                }}
                **defaultOpen={true}**
                value={field.value}
                >
                <SelectTrigger
                    className="disabled:cursor-default py-2 px-0 border-l-0 border-r-0 border-t-0 ring-0 outline-none rounded-none border-b border-border focus-visible:ring-0 focus-visible:border-primary read-only:cursor-default text-[1rem]">
                    <SelectValue />
                </SelectTrigger>
                <SelectContent>
                    {roles?.map((role) => {
                    return (
                    <SelectItem className="capitalize" value={role.name}>
                        {role.name}
                    </SelectItem>
                    );
                    })}
                </SelectContent>
            </Select>
        </FormControl>
        <FormMessage />
    </FormItem>
    )}
/>
Ram Chander
  • 1,088
  • 2
  • 18
  • 36
-1

Another guy from work fixed it. Code is

$(document).ready(function() {
  $.localScroll.hash({
    target: '#realBody'
   });
winchendonsprings
  • 471
  • 2
  • 7
  • 17