zoukankan      html  css  js  c++  java
  • CSS实现鼠标经过网页图标弹出微信二维码



     特点
    1、纯CSS实现二维码展示功能,减少加载JS;

    2、使用CSS3 transform 属性;

    ## 第一步

    在需要展示二维码的地方添加如下代码,其中<a>标签内容可以根据需要修改成图片等,href=”javascript:”表示<a>标签作为按钮使用,不做跳转,实现url访问拦截。

    <a class="weixin" href="javascript:">
    wechat
    </a>


    ## 第二步

    在样式表style.css中添加如下代码

    复制代码
    /*微信二维码*/
    .weixin{
    position:relative;
    }
    .weixin::after{
    content: url(images/qrcode.gif);
    position: absolute;
    right: -28px;
    top: -135px;
    z-index: 99;
    120px;
    height: 120px;
    border: 5px solid #0095ba;
    border-radius: 4px;
    transform-origin: top right;
    transform: scale(0);
    opacity: 0;
    -webkit-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;
    }
    复制代码


    首先父元素添加相对定位,然后以”:after” 伪元素在<a></a>元素的内容之后插入微信二维码;transform: scale(0)和opacity: 0实现二维码隐藏。

    ## 第三步

    同样在style.css中添加如下代码

    .weixin:hover::after{
    transform:scale(1);
    opacity: 1;
    }


    当鼠标经过时显示二维码。



    ## 另一种方法(推荐)

    上面的代码中使用了”:after”伪类元素,是在css中引入二维码文件,其实我们也可以利用img标签将二维码图片放在html中,结构如下:

    <a class="social weixin" href="javascript:">
    <img class="qrcode" src="http://你的路径/qrcode.gif" alt="微信二维码">
    此处为微信图标
    </a>


    自然css样式也要做相应的改变,如下:

    复制代码
    .weixin {
    position: relative;
    }
    
    .weixin img.qrcode {
    position: absolute;
    z-index: 99;
    top: -135px;
    right: -28px;
     7.5rem;
    max- none;
    height: 7.5rem;
    transform: scale(0);
    transform-origin: top right;
    opacity: 0;
    border: .3125rem solid #0085ba;
    border-radius: .25rem;
    -webkit-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;
    
    }
    
    .weixin:hover img.qrcode {
    transform: scale(1);
    opacity: 1;
    }
    复制代码


    transform-origin: 定义二维码图片弹出原点位置,其用法参考CSS3 transform-origin 属性
    无论使用哪一种方式都能够实现鼠标悬停弹出二维码功能,但是个人推荐使用第二种方法,因为这种方法很容易修改二维码路径。
  • 相关阅读:
    甲醛(Formaldehyde)
    Node Embedding
    受限玻尔兹曼机(RBM, Restricted Boltzmann machines)和深度信念网络(DBN, Deep Belief Networks)
    长尾分布,重尾分布(Heavy-tailed Distribution)
    SVD分解与数据压缩
    Batch Normailzation
    Attention Mechanism
    新装的Ubuntu在Nvidia显卡上分辨率不对
    人工神经网络(Artificial Neural Network)
    Xdebug+phpstorm配置
  • 原文地址:https://www.cnblogs.com/lander/p/10027614.html
Copyright © 2011-2022 走看看