首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在javascript中使用'webkit-overflow-scrolling: touch‘?

有没有办法在javascript中使用'webkit-overflow-scrolling: touch‘?
EN

Stack Overflow用户
提问于 2012-06-27 03:24:23
回答 3查看 8.6K关注 0票数 4

我无法通过jquery或原生javascript在DOM中显示此属性。jquery似乎不支持它,我也找不到可以工作的本机名称/语法。有什么帮助吗??

EN

回答 3

Stack Overflow用户

发布于 2012-08-28 22:14:03

正确的语法是

代码语言:javascript
复制
el.style.WebkitOverflowScrolling = 'touch'; // capital W

这(几乎)像通常的命名约定一样,从css到JS,比如border-top正在变成borderTop,...只是webkit的东西得到了大写的第一个字母。

票数 5
EN

Stack Overflow用户

发布于 2012-06-27 03:29:16

对于JavaScript,您需要将破折号-替换为以下大写字母,例如:

代码语言:javascript
复制
var el = document.getElementById('element id');
el.style.webkitOverflowScrolling = 'touch';
票数 0
EN

Stack Overflow用户

发布于 2015-04-14 12:25:50

当使用JavaScript中的样式属性时,在短划线后面的字母大写,因此-webkit- overflow - scroll变为WebkitOverflowScrolling,并确保同时将overflow设置为scroll。

在这里试试:http://jsbin.com/civaha

你可以分辨出它是触摸滚动,因为弹跳。

来源:

代码语言:javascript
复制
<!doctype html>
<meta name=viewport content="initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<title>set touch scrolling in JavaScript - robocat</title>

<script>
function makeScrollable(event) {
    var style = event.target.style;
    style.overflow = 'scroll';
    style.WebkitOverflowScrolling = 'touch'; 
    style.backgroundColor = 'lightyellow';
}
</script>

<body style="margin:0;overflow:hidden;">

<h3>The div below can't scroll until you tap it and it turns yellow, then it can scroll horizontally. . . . </h3>

<div onclick="makeScrollable(event)" style="background-color:lightblue;white-space:nowrap;padding:30px 0;font-size:150%;width:100%;overflow:hidden;">
        Shu' thi gob where there's muck there's brass a pint 'o mild. Be reet will 'e 'eckerslike by 'eck chuffin' nora that's champion. What's that when it's at ooam god's own county. Tha knows nay lad. What's that when it's at ooam. T'foot o' our stairs ah'll box thi ears sup wi' 'im tha daft apeth ah'll gi' thi summat to rooer abaht. Th'art nesh thee ne'ermind. Eeh. How much ah'll gi' thi summat to rooer abaht where's tha bin ne'ermind. How much gerritetten nobbut a lad. Face like a slapped arse bobbar cack-handed. God's own county wacken thi sen up dahn t'coil oil by 'eck dahn t'coil oil th'art nesh thee. A pint 'o mild. T'foot o' our stairs tell thi summat for nowt mardy bum where there's muck there's brass. Chuffin' nora. Sup wi' 'im sup wi' 'im nah then. Dahn t'coil oil tha what will 'e 'eckerslike ah'll learn thi. A pint 'o mild chuffin' nora tha daft apeth shurrup michael palin. Ah'll gi' thi summat to rooer abaht tha what nah then tha knows. Dahn t'coil oil breadcake where's tha bin eeh. Breadcake how much. Bobbar be reet soft southern pansy. Is that thine. God's own county shu' thi gob mardy bum a pint 'o mild. Soft southern pansy breadcake a pint 'o mild.
</div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11214554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档