モバイルデバイス用のHTML5Webアプリケーションを開発していますが、スムーズなアニメーションで少し問題が発生しました。
基本的に、ユーザーがボタンをタップすると、ドロワー(高さ0pxのdiv)が指定された高さ(ピクセル単位)にアニメーション化され、コンテンツがそのドロワーに追加されます。Pinterestアカウントをお持ちの場合は、http://m.pinterest.comでアニメーションをそのまま表示できます([コメント]または[再固定]ボタンをタップします)。
残念な問題は、モバイルデバイスでは、Webkitトランジションがハードウェアアクセラレーションされた高さプロパティではないため、非常に遅く、アニメーションがギザギザになっていることです。
コードスニペットは次のとおりです。
HTML:..。
<div class="pin"> <a class="comment_btn mbtn" href="#" title="" ontouchstart="">Comment</a> <div class="comment_wrapper"> <div class="divider bottom_shadow"></div> <div class="comment"> <!-- Content appended here --> </div> <div class="divider top_shadow" style="margin-top: 0"></div> </div> </div> <div class="pin"> ... </div>
CSS:
.comment_wrapper { -webkit-transition: all 0.4s ease-in-out, height 0.4s ease-in-out; position: relative; overflow: hidden; width: 100%; float: left; height: 0; } .comment { background: #f4eeee; margin-left: -10px; padding: 10px; height: 100%; width: 100%; float: left; }
Javascript(jQueryを使用):
function showSheet(button, wrapper, height) { // Animate the wrapper in. var css = wrapper.css({ 'height': height + 'px', 'overflow': 'visible', 'margin-bottom': '20px', 'margin-top': '10px' }); button.addClass('pressed'); } $('.comment_btn').click(function() { showSheet($(this), $(this).siblings('.comment_wrapper'), 150); });
スクリーンショット:http ://imgur.com/nGcnS,btP3W
Webkit Transformsで発生した、完全には理解できない問題は次のとおりです。
- Webkit Transformsはコンテナーの子をスケーリングしますが、これは私がやろうとしていることには望ましくありません。
-webkit-transform: none
子供に適用すると、この動作がリセットされないようです。 - Webkitトランスフォームは兄弟要素を移動しません。そのため、
.pin
操作しているコンテナの後のコンテナは自動的に下に移動しません。これは手動で修正できますが、面倒です。
どうもありがとう!