SVG路径遮罩实现实物图片颜色任意替换

所属分类: 网页特效-实用工具    2024-12-06 09:26:57

SVG路径遮罩实现实物图片颜色任意替换 ie兼容10
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

SVG路径遮罩实现实物图片颜色任意替换(共6个文件)

    • index.html

使用方法

var background = ["#24243e", "#302b63"];
const body = document.getElementsByTagName("body")[0];
const couch = document.getElementById("js-couch");
const col1 = document.getElementById("js-color-1");
const col2 = document.getElementById("js-color-2");
const col3 = document.getElementById("js-color-3");

function updateCouch(picker, string) {
  if (!string) {
  couch.style.fill = picker.toHEXString();
    } else {
      // Used when generating random
      couch.style.fill = string;
     setTimeout(function(){couch.classList.remove("fade");}, 700); 
    }
}

function updateBackgroundD(picker, randArray) {
 if (!randArray) {
  background[0] = picker.toHEXString();
  } else {
    background[0] = randArray[0];
  }
  body.style.background =
    "linear-gradient(to right, " +
    background[0] +
    " , " +
    background[1] +
    " , " +
    background[0] +
    ")";
}

function updateBackgroundL(picker, randArray) {
 if (!randArray) {
  background[1] = picker.toHEXString();
  } else {
    background[1] = randArray[1];
  }
  
  body.style.background =
    "linear-gradient(to right, " +
    background[0] +
    " , " +
    background[1] +
    " , " +
    background[0] +
    ")";
}


// Generate random



function generateRandom() {
// Couch  
var red = Math.floor(Math.random() * 256) ;
var green = Math.floor(Math.random() * 256) ;
var blue = Math.floor(Math.random() * 256) ;
// Grad 1
var grad_1_r = Math.floor(Math.random() * 256) ;
var grad_1_g = Math.floor(Math.random() * 256) ;
var grad_1_b = Math.floor(Math.random() * 256) ;
// Grad 2  
var grad_2_r = grad_1_r >= 206 ? grad_1_r : grad_1_r + 50;
var grad_2_g = grad_1_g >= 206 ? grad_1_g : grad_1_g + 50;
var grad_2_b = grad_1_b >= 206 ? grad_1_b : grad_1_b + 50;
  
let hex = rgbToHex(red, green, blue);
let grad_1_hex = rgbToHex(grad_1_r, grad_1_g, grad_1_b);
let grad_2_hex = rgbToHex(grad_2_r, grad_2_g, grad_2_b);
  
let gradient = [grad_1_hex, grad_2_hex];
  
  updateCouch(null, hex);
  updateBackgroundD(null, gradient);
  updateBackgroundL(null, gradient);
  
    couch.classList.add("fade");
  
 document.getElementById('js-color-1')
    .jscolor.fromString(hex);
  
 document.getElementById('js-color-2')
    .jscolor.fromString(grad_1_hex);
  
   document.getElementById('js-color-3')
    .jscolor.fromString(grad_2_hex);
}

function componentToHex(c) {
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery自动计算屏幕分辨率以及鼠标DPI插件

一款点击页面任意地方可计算DPI插件,鼠标点击页面任意地方,可自动计算屏幕分辨率以及鼠标的DPI(每英寸点数)。
  实用工具
 2693  0

jquery跨浏览器全屏助手插件

一个跨浏览器HTML5全屏API助手,允许在全屏模式下显示任何指定的DIV内容或整个页面内容。
  实用工具
 8690  0

jquery按原子序数排序的标准元素周期表

使用jQuery、JSON和CSSGrid创建一个按原子序数排序的标准元素周期表(118个元素),鼠标悬停即可显示详细信息。
  实用工具
 8719  0

简易可选颜色的在线绘图插件

一个轻量级绘图板(画笔工具)插件,支持手机移动端上HTML5画布元素上绘制平滑的线条和曲线。
  实用工具
 1902  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论