2017-11-24 2 views
0

iOSアプリケーションにHTML、Javaスクリプトコードをロードしています。それはうまく動作しますが、デバイスの高さに応じて、アニメーションのサイズ(幅)を変更する必要があります。次のコードを試しましたが、iOSに呼び出すjavascriptの新機能です。iOSで動的にコンテナの幅を変更する方法(Objective-C)

Javaスクリプトの私のhtmlページのコードが

  var $ios9 = document.getElementById('container-ios9'); 
     var SW9 = new Wave9({ 
           width: 800, 
           height: 40, 
           container: $ios9, 
           }); 
     </script> 

であり、私は上記のコードは、幅を変更されていない

if (self.view.frame.size.width <= 400) { 
[_animationWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('container-ios9').width = 500"]; 
} 
else { 
    [_animationWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('container-ios9').width = 700"]; 
} 

としてネイティブコードに呼び出しています、だから、 は誰も私を提案することができます、これを修正する方法。ありがとう!

+0

私は 'のdocument.getElementById( 'コンテナios9')。width'が間違っていると思います。 document.getElementById( 'container-ios9')。style.width' – Sankar

+0

これは正しいことを意味する[_animationWebView stringByEvaluatingJavaScriptFromString:@ "document.getElementById( 'container-ios9')。style.width = 400"] ; ? –

+0

はい。また、 'document.getElement ById( 'container-ios9').style.width = '400px''試しましたか? – Sankar

答えて

0

多くのR & Dの後、私は自分で問題を解決しました。私はここでこの答えを掲示しています、それは将来誰かを助けるでしょう。

HTMLファイルで

、Javaのスクリプトコード、

   if (window.screen.width <= 400) { 
     var $ios9 = document.getElementById('container-ios9'); 
     var SW9 = new Wave9({ 
           width: 800, 
           height: 40, 
           container: $ios9, 
           }); 
} else { 
//other devices 
     </script> 
関連する問題