pavlovm503 4 năm trước cách đây
mục cha
commit
9b8cf2cc96

+ 43 - 0
Pavlov_hm11/css/clean.css

@@ -0,0 +1,43 @@
+ html, body, div, span, applet, object, iframe,
+    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+    a, abbr, acronym, address, big, cite, code,
+    del, dfn, em, img, ins, kbd, q, s, samp,
+    small, strike, strong, sub, sup, tt, var,
+    b, u, i, center,
+    dl, dt, dd, ol, ul, li,
+    fieldset, form, label, legend,
+    table, caption, tbody, tfoot, thead, tr, th, td,
+    article, aside, canvas, details, embed, 
+    figure, figcaption, footer, header, hgroup, 
+    menu, nav, output, ruby, section, summary,
+    time, mark, audio, video {
+    	margin: 0;
+    	padding: 0;
+    	border: 0;
+    	font-size: 100%;
+    	font: inherit;
+    	vertical-align: baseline;
+    }
+    /* HTML5 display-role reset for older browsers */
+    article, aside, details, figcaption, figure, 
+    footer, header, hgroup, menu, nav, section {
+    	display: block;
+    }
+    body {
+    	line-height: 1;
+    }
+    ol, ul {
+    	list-style: none;
+    }
+    blockquote, q {
+    	quotes: none;
+    }
+    blockquote:before, blockquote:after,
+    q:before, q:after {
+    	content: '';
+    	content: none;
+    }
+    table {
+    	border-collapse: collapse;
+    	border-spacing: 0;
+    }

+ 15 - 0
Pavlov_hm11/css/style.css

@@ -0,0 +1,15 @@
+body{
+    overflow: hidden;
+}
+img {
+    border-radius: 50%
+}
+#control4{
+    height: 362px;
+    width: 362px;
+    border-radius: 50%;
+    border:solid 10px pink;
+}
+#control1,#control2,#control3,#control4{
+    display: inline-block;
+}

BIN
Pavlov_hm11/img/1@3x.png


BIN
Pavlov_hm11/img/soska.png


+ 16 - 0
Pavlov_hm11/inddex.html

@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>Pavlov_Maik_FSA3</title>
+    <link rel="stylesheet" href="css/clean.css">
+	<link rel="stylesheet" href="css/style.css">
+</head>
+<body>
+	<div id="control1"></div>
+	<div id="control2"></div>
+	<div id="control3"></div>
+	<div id="control4"></div>
+	<script src="script/script.js"></script>
+</body>
+</html>

+ 89 - 0
Pavlov_hm11/script/script.js

@@ -0,0 +1,89 @@
+function Control(el, {min=0, 
+                      max=100, 
+                      step=1, 
+                      value=100, 
+                      onChange, 
+                      minAngle=0, 
+                      wheelStepRatio=0.01,
+                      maxAngle=360,
+                      src='img/1@3x.png'} = {}){
+    
+    const img = document.createElement('img');
+    el.appendChild(img);
+    img.src = src;
+    const angleRatio = (maxAngle - minAngle) / (max - min);
+    
+    const getAngle = () => { 
+        const offset = value - min;
+        const angleOffset = offset * angleRatio;
+        const angle = minAngle + angleOffset;
+        return angle
+    };
+    
+    const updateImg = (angle=getAngle()) => img.style.transform = `rotate(${angle}deg)`;
+    updateImg();
+
+    const updateValue = (st=step) => {
+        value >= max ? value -= max : value < 0 ? value += max : value;
+        value += st;
+        updateImg();
+    };
+
+    img.onclick = (e) => {
+        console.log(e);
+        const {x: imgX, width: imgWidth } = img.getBoundingClientRect();
+        const xOnImg = e.clientX - imgX;
+        const st = xOnImg > imgWidth/2 ? step: -step;
+        updateValue(st);
+    };
+
+    img.onmousewheel = e => {
+        const st = e.deltaY*wheelStepRatio;
+        updateValue(st);
+    };
+
+    const toDeg = rad => (360/(2*Math.PI))*rad;
+    let start;
+    
+    const getAngleByCoords = (x, y) => {
+        const {x: imgX, y: imgY, width, height} = img.getBoundingClientRect();
+        const xOnImg = e.clientX - imgX - width/2;
+        const yOnImg = e.clientY - imgY - height/2;
+        return toDeg(Math.atan2(yOnImg, xOnImg));
+    };
+
+    img.onmousedown = e => {
+        start = getAngleByCoords(e);
+        e.preventDefault();
+    };
+    img.onmousemove = e => {
+        if (e.buttons && start){
+        const angleDiff = getAngleByCoords(e)- startAngle;
+        const angle = getAngle();
+        updateImg(angle + angleDiff);
+        };
+    };
+    img.onmouseup = e => {
+        let inValue = endAngle / ((maxAngle - minAngle) / (max - min))%100;
+        value = inValue < 0 ? 75 + (25 + inValue) : inValue;
+        updateImg(endAngle);
+    };
+    this.getValue = function () {
+		return Math.floor(value);
+    }
+}
+let controlRed = new Control(control1, max = 255);
+let controlGreen = new Control(control2, max = 255);
+let controlBlue = new Control(control3, max = 255);
+
+controlRed.setValue;
+controlGreen.setValue;
+controlBlue.setValue;
+
+let body = document.querySelector('body');
+body.onmousemove = () => {            //я запутался и не понял как по другому 
+	control4.style = `background:rgba(${controlRed.getValue()},${controlGreen.getValue()},${controlBlue.getValue()},1);`;
+	control1.style = `width:362px;height:362px;border-radius: 50%;border: solid 10px rgb(${controlRed.getValue()},0,0);background:rgb(${controlRed.getValue()},0,0)`;
+	control2.style = `width:362px;height:362px;border-radius: 50%;border: solid 10px rgb(0,${controlGreen.getValue()},0);background:rgb(0,${controlGreen.getValue()},0)`;
+	control3.style = `width:362px;height:362px;border-radius: 50%;border: solid 10px rgb(0,0,${controlBlue.getValue()}); background:rgb(0,0,${controlBlue.getValue()});`;
+};