Draggables手机壳颜色拖拽颜色更换效果代码

代码语言:html

所属分类:拖放

代码描述:Draggables手机壳颜色拖拽颜色更换效果代码

代码标签: 颜色 拖拽 颜色 更换 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">

  
<style>
* {
  box-sizing: border-box;
}

body {
  overflow-x: hidden;
}

color-sidebar {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px;
  z-index: 2;
  touch-action: none;
}

color-picker {
  display: block;
  position: relative;
}

color-item,
color-draggable {
  display: block;
  border-radius: 50%;
  visibility: hidden;
  opacity: 0;
  box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.26);
  cursor: move;
  cursor: -webkit-grab;
  cursor: grab;
}

color-item {
  position: relative;
  margin: 10px 10px 0 10px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
}

color-draggable {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: absolute;
}

color-draggable.dragging {
  cursor: -webkit-grabbing;
  cursor: grabbing;
}

.phone-content {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 31px;
  background: linear-gradient(white, #f2f2f2);
}

phone-container {
  display: block;
  position: relative;
  width: 56.3555347092vmin;
  padding-top: 159.7003745318%;
  visibility: hidden;
  opacity: 0;
}

#phone-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible !important;
}

#phone-mask-path {
  fill: #fff;
  stroke: #fff;
  stroke-width: 4;
}

#phone-outline {
  fill: white;
  stroke: white;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  opacity: 0;
  stroke: rgba(0, 0, 0, 0.2);
}
</style>



</head>

<body >
  <section class="phone-content">
  <phone-container>      
    <svg id="phone-svg" viewBox="0 0 1335 2132">
      
      <filter id="drop-shadow" x="-100%" y="-100%" width="300%" height="300%">
        <feGaussianBlur id="shadow-blur" in="SourceAlpha" stdDeviation="50"/>
        <feOffset dx="0" dy="0" result="offsetblur"/>
        <feFlood id="shadow-color" flood-color="#fff"/>
        <feComposite in2="offsetblur" operator="in"/>
        <feMerge>
          <feMergeNode/>
          <feMergeNode in="SourceGraphic"/>
        </feMerge>
      </filter>
      
      <mask id="phone-mask" maskUnits="userSpaceOnUse">
        <path id="phone-mask-path" d="M390.001733,1932.5 C390.001733,1932.5 565.999988,1931.5 586.05712,1931.5 C606.114252,1931.5 617.023773,1915.5 620.828278,1915.5 C660.021292,1915.5 735.169897,1915.5 737.998019,1915.5 C740.826141,1915.5 746.051941,1931.5 778.812117,1931.5 C811.572292,1931.5 971.998267,1932.5 971.998267,1932.5 C1043.24228,1932.5 1106,1869.76062 1106,1797.49805 L1106,338.501954 C1106,255.587048 1040.06342,200.5 978.998267,200.5 L903.563583,200.5 C877.936549,200.5 860.246162,215.5 860.246162,215.5 L797.920589,215.5 C797.920589,215.5 776.386439,200.5 760.492377,200.5 C744.598316,200.5 379.001733,200.5 379.001733,200.5 C307.757721,200.5 250,260.459622 251,340.704544 L251,604.642372 L258,630.93573 L258,745.743147 L251,769.688698 L251,865.914447 L258,887.652675 L258,1128.96869 L251,1148.60567 L252,1791.49805 C252,1878.48584 318.756326,1932.5 390.001733,1932.5 Z" />
      </mask>
                          
      <path id="phone-outline" filter="url(#drop-shadow)" d="M390.001733,1932.5 C390.001733,1932.5 565.999988,1931.5 586.05712,1931.5 C606.114252,1931.5 617.023773,1915.5 620.828278,1915.5 C660.021292,1915.5 735.169897,1915.5 737.998019,1915.5 C740.826141,1915.5 746.051941,1931.5 778.812117,1931.5 C811.572292,1931.5 971.998267,1932.5 971.998267,1932.5 C1043.24228,1932.5 1106,1869.76062 1106,1797.49805 L1106,338.501954 C1106,255.587048 1040.06342,200.5 978.998267,200.5 L903.563583,200.5 C877.936549,200.5 860.246162,215.5 860.246162,215.5 L797.920589,215.5 C797.920589,215.5 776.386439,200.5 760.492377,200.5 C744.598316,200.5 379.001733,200.5 379.001733,200.5 C307.757721,200.5 250,260.459622 251,340.704544 L251,604.642372 L258,630.93573 L258,745.743147 L251,769.688698 L251,865.914447 L258,887.652675 L258,1128.96869 L251,1148.60567 L252,1791.49805 C252,1878.48584 318.756326,1932.5 390.001733,1932.5 Z" />
      
      <g>
        <rect id="background" fill="#b8c2de" width="100%" height="100%" mask="url(#phone-mask)" /> 
        <g id="ripple-layer" mask="url(#phone-mask)"></g>
      </g>      
      <image x="1" y="1" width="1333px" height="2130px" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/phone.png?v=1" /> 
    </svg>   
  </phone-container>
</section>    
  
<section class="color-content">
  <color-sidebar>      
    <color-picker></color-picker>    
  </color-sidebar>   
</section>

  <script>
      (function() {
  
  "use strict";
  
  function getContour(bezier, tolerance) {
    
    if (tolerance == null) {
      tolerance = 1;
    }
    
    var size  = bezier.length;
    var first = bezier[0];
    var last  = bezier[size - 1];    
    var prev  = first;
    
    var x0 = first.x;
    var y0 = first.y;

    var points = [first];
    var coords = [first.x, first.y];  
    
    for (var i = 1; i < size; i += 3) {
    
      var p1 = prev;
      var p2 = bezier[i];
      var p3 = bezier[i+1];
      var p4 = bezier[i+2];
      
      addPoint(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);
      prev = p4;
    } 

    points.push(last);
    coords.push(last.x, last.y);
    
    return points;
    
    function addPoint(x1, y1, x2, y2, x3, y3, x4, y4) {
    
      // Calculate all the mid-points of the line segments
      var x12 = (x1 + x2) / 2;
      var y12 = (y1 + y2) / 2;
      var x23 = (x2 + x3) / 2;
      var y23 = (y2 + y3) / 2;
      var x34 = (x3 + x4) / 2;
      var y34 = (y3 + y4) / 2;

      var x123  = (x12 + x23) / 2;
      var y123  = (y12 + y23) / 2;
      var x234  = (x23 + x34) / 2;
      var y234  = (y23 + y34) / 2;
      var x1234 = (x123 + x234) / 2;
      var y1234 = (y123 + y234) / 2;

      // Try to approximate the full cubic curve by a single straight line
      var dx = x4 - x1;
      var dy = y4 - y1;

      var d2 = Math.abs(((x2 - x4) * dy - (y2 - y4) * dx));
      var d3 = Math.abs(((x3 - x4) * dy - (y3 - y4) * dx));

      if ((d2 + d3) * (d2 + d3) < tolerance * (dx * dx + dy * dy)) {
        points.push({ x: x1234, y: y1234 });    
        coords.push(x1234, y1234); 
        return;
      }

      // Continue subdivision
      addPoint(x1, y1, x12, y12, x123, y123, x1234, y1234);
      addPoint(x1234, y1234, x234, y234, x34, y34, x4, y4);    
    }
  }  
  
  window.getContour = getContour;
})();

  </script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/simplify.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Draggable.1.20.3.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/MorphSVGPlugin.js"></script>
      <script>
"use strict";
console.clear();
const log = console.log.bind(console);
const svgns = "http://www.w3.org/2000/svg";
SVGElement.prototype.getTransformToElement = SVGElement.prototype.getTransformToElement || function (toElement) {
    return toElement.getScreenCTM().inverse().multiply(this.getScreenCTM());
};
//
// RIPPLE
// =========================================================================== 
class Ripple {
    constructor(x, y, color) {
        this.color = color;
        this.element = document.createElementNS(svgns, "circle");
        const dx = x - offsetX;
        const dy = y - offsetY;
        const element = this.element;
        const radius = this.getRadius(dx, dy, phoneRect.w.........完整代码请登录后点击上方下载按钮下载查看

网友评论0