簡體   English   中英

任何方式應用'webkit-overflow-scrolling:touch'內嵌javascript?

[英]Any way to apply 'webkit-overflow-scrolling: touch' inline with javascript?

無法通過jquery或本機javascript在DOM中顯示此屬性。 jquery似乎不支持它,我找不到有效的本機名稱/語法。 任何幫助?

正確的語法是

el.style.WebkitOverflowScrolling = 'touch'; // capital W

這幾乎就像從css到JS的通常命名約定一樣,border-top正在成為borderTop,...只是webkit的東西得到了一個首字母。

使用JavaScript,您需要替換破折號-使用以下大寫字母,例如:

var el = document.getElementById('element id');
el.style.webkitOverflowScrolling = 'touch';

在JavaScript中使用style屬性時,請使用dash之后的字母大寫,因此-webkit-overflow-scrolling變為WebkitOverflowScrolling並確保還設置overflow以滾動。

在這里試試: http//jsbin.com/civaha

由於彈跳,你可以說它是觸摸滾動。

資源:

<!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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM