微信小程序开发-分享或转发悬浮按钮

通过给 button 组件设置属性open-type="share",可以在用户点击按钮后触发 [Page.onShareAppMessage]事件,如果当前页面没有定义此事件,则点击后无效果。

wxml文件

    <view class='share'>
       <image src='../../images/forward.png'></image>
       <text>分享</text>
      <button hoverClass="btn-hover" open-type='share' ></button>
    </view>

wxss文件

  .share { 
    height: 95rpx;
    width: 95rpx;
    position: fixed;
    bottom: 170rpx;
    right: 40rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 24rpx;
    background: #15aa07;
    border-radius: 50%;
    z-index: 10;
    opacity: 0.9;  透明度
    top: 1150rpx;
  } 
  .share image {
    height: 70rpx;
    width: 70rpx;
  }
  .share text {
    color: #fff;
    font-weight: bold; 
  }
   
  .share button {
    position: absolute;
    height: 100%;
    width: 100%;
    opacity: 0.1;
    z-index: 99;
  }

  .btn-hover {
    background: #033f18;   //点击效果,颜色不必太深
    border-radius: 50px;    //圆角处理
}

效果

效果图

代码下载

地址:https://github.com/wxplug/add-tips 欢迎star

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容