admin管理员组

文章数量:1335825

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

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

Share Improve this question edited Jun 27, 2011 at 23:11 winchendonsprings asked Jun 27, 2011 at 19:33 winchendonspringswinchendonsprings 4912 gold badges8 silver badges18 bronze badges 5
  • Can you provide a code sample? – xanderer Commented Jun 27, 2011 at 19:34
  • On which DOM element(s) are you handling key events? – Greg Hewgill Commented Jun 27, 2011 at 19:34
  • @xanderer No code example, As simple as I can put it is, Loadpage, try to scroll with pagedown or arrow down, can't, click anywhere, now you can scroll with keys. – winchendonsprings Commented Jun 27, 2011 at 19:38
  • @Greg Hewgill, I'm not sure, can I check that with the DOM tab on firebug? – winchendonsprings Commented Jun 27, 2011 at 19:39
  • @winchendonsprings darn, I would like at @WEFX answer. No link to the page either? – xanderer Commented Jun 27, 2011 at 19:40
Add a ment  | 

5 Answers 5

Reset to default 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?

remove the hash mark '#'.

Or if your using jQuery

 $(function() {
      $('#realBody').focus();
 });

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./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 :)

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>
    )}
/>

Another guy from work fixed it. Code is

$(document).ready(function() {
  $.localScroll.hash({
    target: '#realBody'
   });

本文标签: javascriptWeb page will not scroll with keys until clickedStack Overflow