前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >it图片过滤灰色兼容

it图片过滤灰色兼容

作者头像
刘嘿哈
发布2022-10-25 14:22:14
7590
发布2022-10-25 14:22:14
举报
文章被收录于专栏:js笔记js笔记
代码语言:javascript
复制
<template>
    <div :style="`width:${width}px;height:${height}px`">
      <img :src="imgSrc" v-if="!isGray||!isIE11">
      <div v-else>
        <svg overflow="hidden" preserveAspectRatio="none slice" :width="width" :height="height">
         <image overflow="visible" preserveAspectRatio="none slice" x='0' y='0' :width="width" :height="height" :xlink:href="imgSrc" filter="url(#grayscle)"></image>

        </svg>
      </div>
    </div>
</template>

<script>
    export default {
        name:"grayImg",
        props:{
            imgSrc:{
                type:String,
                default:""
            },
            width:{
                type:[Number,String],
                default:150
            },
            height:{
                type:[Number,String],
                default:90
            }
        },
        computed: {
            isGray() {
                return window.sessionStorage.getItem('skin')=='default';
            },
            isIE11(){
                return navigator.userAgent.indexOf('Trident')!==-1;
            }
        },
        
    }
</script>

<style lang="scss" scoped>
img{
    height:100%;
    width:100%;
}
</style>



// <template>
//    <svg xmlns=" http://www.w3.org/2000/svg" style="display:none">
//      <filter  id="grayscale">
//        <feColorMatrix type="matrix"values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
//      </filter>
//    </svg>
// </template>

// <script>
//     export default {
//         name:"grayscale"
//     }
// </script>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-08-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档