gpt4 book ai didi

javascript - 在没有滚动条的情况下滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:35:14 29 4
gpt4 key购买 nike

示例表格:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
* {font:13px arial; color:white;}
body {background:black;}
label {display:inline-block; width:50px;}
input, textarea {margin:0; border:1px solid red; padding:0; background:green;}
textarea {width:300px; height:100px;}
</style>
</head>
<body>
<form action="#">
<div><label for="entry_0">Name</label><input type="text" id="entry_0"></div>
<div><label for="entry_1">Email</label><input type="text" id="entry_1"></div>
<div><label for="entry_2">URL</label><input type="text" id="entry_2"></div>
<div id="parent"><textarea id="entry_3"></textarea></div>
<div><input type="submit" value="Submit"></div>
</form>
</body>
</html>

我想删除/隐藏 textarea 滚动条,因为它与我的表单样式不匹配。我知道我可以使用 jQuery 插件来设置滚动条的样式,但它们不能跨不同的浏览器/系统可靠地工作。要隐藏滚动条,我可以使用 textarea {width:300px;高度:100px; overflow:hidden;},但它完全阻止了 Firefox 在鼠标和键盘上的滚动。我还尝试了以下解决方法:

#parent {width:284px; height:102px; overflow:hidden;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}

如果我添加一些脚本来计算父分区宽度,它应该可以准确地工作:

var textareaWidth = document.getElementById('entry_3').scrollWidth;
document.getElementById('parent').style.width = textareaWidth + 'px';

但无论如何,上述方法似乎在 Chrome/Safari 中不起作用。
演示:http://jsfiddle.net/RainLover/snTaP/

在 Chrome/Safari 中打开上面的演示 >> 将一些文本插入文本区域 >> 突出显示/选择一行并将鼠标向右拖动,您将看到滚动条。或者使用键盘键 Page UpPage Down

任何更正或其他解决方案?

最佳答案

Hacky 但似乎工作...

使用::after伪元素

#parent {width:302px; overflow:hidden; position: relative;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}
textarea:focus {
outline-offset: 0;
outline-style: none;
}

#parent::after {
position: absolute;
width: 17px;
top: 0;
right: 0px;
height: 102px;
border-left:1px solid red;
background-color: black;
content: "";
display: block;
}

http://jsfiddle.net/tarabyte/snTaP/3/

或使用额外的 div

HTML:

<div id="parent">
<textarea id="entry_3"></textarea>
<div id="hidescroll"></div>
</div>

CSS:

#parent {width:302px; overflow:hidden; position: relative;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}
textarea:focus {
outline-offset: 0;
outline-style: none;
}
#hidescroll {
position: absolute;
width: 17px;
top: 0;
right: 0;
z-index: 1000;
height: 102px;
border-left:1px solid red;
background-color: black;
}

http://jsfiddle.net/tarabyte/snTaP/2/

关于javascript - 在没有滚动条的情况下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752641/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com