ホームページ  >  記事  >  ウェブフロントエンド  >  WeChat アプレットの商品詳細ページの下部にあるポップアップ ボックスを実現する方法

WeChat アプレットの商品詳細ページの下部にあるポップアップ ボックスを実現する方法

php中世界最好的语言
php中世界最好的语言オリジナル
2018-06-02 10:22:413707ブラウズ

今回は、WeChat Mini プログラム 商品詳細 ページの下部にポップアップ ボックスを実装する方法と、WeChat Mini の下部にポップアップ ボックスを実装するための 注意事項 について説明します。プログラムの製品詳細ページです。実際のケースを見てみましょう。

1.js コード (通常は、ダイアログ ボックスを表示する関数のみが呼び出されます。ダイアログ ボックスの外側をクリックすると、ダイアログ ボックスが消える場合があります)

//显示对话框
 showModal: function () {
  // 显示遮罩层
  var animation = wx.createAnimation({
   duration: 200,
   timingFunction: "linear",
   delay: 0
  })
  this.animation = animation
  animation.translateY(300).step()
  this.setData({
   animationData: animation.export(),
   showModalStatus: true
  })
  setTimeout(function () {
   animation.translateY(0).step()
   this.setData({
    animationData: animation.export()
   })
  }.bind(this), 200)
 },
 //隐藏对话框
 hideModal: function () {
  // 隐藏遮罩层
  var animation = wx.createAnimation({
   duration: 200,
   timingFunction: "linear",
   delay: 0
  })
  this.animation = animation
  animation.translateY(300).step()
  this.setData({
   animationData: animation.export(),
  })
  setTimeout(function () {
   animation.translateY(0).step()
   this.setData({
    animationData: animation.export(),
    showModalStatus: false
   })
  }.bind(this), 200)
 }

2.wxss コード

/*使屏幕变暗 */
.commodity_screen {
 width: 100%;
 height: 100%;
 position: fixed;
 top: 0;
 left: 0;
 background: #000;
 opacity: 0.2;
 overflow: hidden;
 z-index: 1000;
 color: #fff;
}
/*对话框 */
.commodity_attr_box {
 height: 300rpx;
 width: 100%;
 overflow: hidden;
 position: fixed;
 bottom: 0;
 left: 0;
 z-index: 2000;
 background: #fff;
 padding-top: 20rpx;
}

3.wxml コード (showModalStatus 変数) js コードのデータ オブジェクトで初期化するには、最初はダイアログ ボックスが表示されなかったため、false に初期化します)

 <!--屏幕背景变暗的背景 -->
 <view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view>
 <!--弹出框 -->
 <view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}">在这里写弹出框里面的布局</view>

この記事の事例を読んだ後は、この方法を習得したと思います。 、PHP 中国語 Web サイトの他の関連記事にも注目してください。

推奨読書:

vue でフィルターを使用する方法

vue を使用して dom のクラスを決定する方法

以上がWeChat アプレットの商品詳細ページの下部にあるポップアップ ボックスを実現する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。