【问题标题】:Any way to apply 'webkit-overflow-scrolling: touch' inline with javascript?任何方式应用'webkit-overflow-scrolling:触摸'内联与javascript?
【发布时间】:2012-06-26 19:24:22
【问题描述】:

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

【问题讨论】:

    标签: javascript ios safari webkit


    【解决方案1】:

    正确的语法是

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 这对我在 Safari 或 Chrome 上不起作用。你能确认这特别适用于“webkit-overflow-scrolling”吗??
      【解决方案3】:

      在 JavaScript 中使用 style 属性时,破折号后的字母大写,因此 -webkit-overflow-scrolling 变为 WebkitOverflowScrolling 并确保也将溢出设置为滚动。

      在这里试试: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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-04
        • 2012-02-13
        • 2014-09-27
        相关资源
        最近更新 更多