diff options
| Commit | 948c1006729bfdcd2b5937e7c240c4df3294290e (patch) | |
|---|---|---|
| Author | 2023-01-03 16:50:55 +0200 | |
| Committer | 2023-01-03 16:50:55 +0200 | |
| Files | ee53dc453736c52f1de44ab8cd3b1fc2442e0ca6 | |
| uni-projects-948c1006729bfdcd2b5937e7c240c4df3294290e.tar uni-projects-948c1006729bfdcd2b5937e7c240c4df3294290e.tar.gz uni-projects-948c1006729bfdcd2b5937e7c240c4df3294290e.zip | ||
| Parent | 76f4cc6c031b93c7e74e8d8ccd40536bf917c215 (diff) | |
[WGL/HW11] Simplified drag bar logic
1 files changed, 8 insertions, 9 deletions
| -rw-r--r-- | Year 2/Computer Graphics with WebGL/Homework 11 - The graph/Homework.html | 17 |
diff --git a/Year 2/Computer Graphics with WebGL/Homework 11 - The graph/Homework.html b/Year 2/Computer Graphics with WebGL/Homework 11 - The graph/Homework.html index 70a553c..18760da 100644 --- a/Year 2/Computer Graphics with WebGL/Homework 11 - The graph/Homework.html +++ b/Year 2/Computer Graphics with WebGL/Homework 11 - The graph/Homework.html @@ -95,17 +95,20 @@ slright = document.getElementById("sl-right");
var inside = false;
+ var clicked = 0;
slleft.onmouseenter = slright.onmouseenter = function () {
inside = true;
}
slleft.onmouseleave = slright.onmouseleave = function () {
inside = false;
+ clicked = 0;
}
- var clicked = 0;
+
var initialPosition = 0;
var current = 0;
var leftCurrent = 0;
var rightCurrent = 0;
+
slleft.onmousedown = slright.onmousedown = function (e) {
clicked = (this.id == "sl-left") ? 1 : 2;
initialPosition = e.clientX;
@@ -126,10 +129,8 @@ slleft.onmousemove = function (e) {
if (!inside || clicked != 1) return;
var newCurr = current + initialPosition - e.clientX;
- if ((newCurr > leftCurrent) && // if we move left
- (slright.offsetWidth * 0.4 - leftCurrent < 10)) return;
- if ((newCurr < leftCurrent) && // if we move right
- (slleft.offsetWidth * 0.4 - leftCurrent >= slright.offsetWidth * 0.6 - rightCurrent - 50)) return;
+ if ((newCurr > leftCurrent) && (slleftPos() < 10)) return;
+ if ((newCurr < leftCurrent) && (slleftPos() >= slrightPos() - 50)) return;
this.style.transform = "translateX(calc(-60% - " + (leftCurrent = newCurr) + "px))";
changed = true;
@@ -138,10 +139,8 @@ slright.onmousemove = function (e) {
if (!inside || clicked != 2) return;
var newCurr = current + initialPosition - e.clientX;
- if ((newCurr < rightCurrent) && // if we move right
- (slright.offsetWidth * 0.4 + rightCurrent < 10)) return;
- if ((newCurr > rightCurrent) && // if we move left
- (slleft.offsetWidth * 0.4 - leftCurrent >= slright.offsetWidth * 0.6 - rightCurrent - 50)) return;
+ if ((newCurr < rightCurrent) && (slrightPos() > slright.offsetWidth - 10)) return;
+ if ((newCurr > rightCurrent) && (slleftPos() >= slrightPos() - 50)) return;
this.style.transform = "translateX(calc(60% - " + (rightCurrent = newCurr) + "px))";
changed = true;
|
