diff options
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;
|
