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
5 Answers
Reset to default 4Perhaps 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
版权声明:本文标题:javascript - Web page will not scroll with keys until clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399330a2467565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论