快推365SEO问答正文

如何添加一键拨号悬浮按钮?

2020/12/14 11:40:52

841浏览量

回答

2020/12/14 11:41:50

swan部分(放在每个swan页面最后),图片最好自己下载上传到自己的站点,再修改下面的图片地址:

<view class="tel__wrap">

   <button class="button10" bindtap="calling_tel">

<image class="tel_image" src="https://static.51jiancong.com/wxapp/936/images/20190612/20190612085712_16199.png"></image>

</button>

</view>





css部分(只需放在index.css最后的空白位置即可):

.tel__wrap {

position:fixed;right:26rpx;bottom:30rpx;z-index:999;

}

.tel__wrap .tel_image {

width:80rpx;height:80rpx;visibility:visible;opacity:0.6;

}

.tel__wrap .button10 {

visibility:hidden;margin:0;

}


js部分(放在每个js页面最后的   });  前面):

,calling_tel: function (e) {

   let mobile = e.currentTarget.dataset.id;

   if (!mobile) {

     mobile = app.globaldata.settings.cfg_kefu_tel;

   }

   swan.makePhoneCall({

     phoneNumber: mobile,

     success: function () {

       console.log("拨打电话成功!")

     },

     fail: function () {

       console.log("拨打电话失败!")

     }

   })

 }




此教程来源于《搜外网-夫唯SEO培训》,网址:https://www.seowhy.com/

本教程连接:https://www.seowhy.com/a/1573.html,为原创表示感谢!


0+1

0+1