This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (41 loc) · 1.53 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$( document ).ready( function () {
// DOM SELECTORS:
var $container = $( '#container' );
var $planeA = $( '.plane-a' );
var $slider = $( '#slider' );
// OTHER GLOBAL VARIABLES:
var limitLeft = $container.offset().left;
var limitRight = limitLeft + $container.width();
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
// EVENTLISTENERS:
$slider.mousedown( function ( event ) {
event.stopPropagation();
event.preventDefault();
// on mousedown we pass the control to moveSlider fn.
moveSlider();
} );
$container.mouseup(function (event) {
event.stopPropagation();
// on mouseup we stop listening to the mouse movements.
$container.off('mousemove');
});
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
// FUNCTIONS DECLARATION:
function moveSlider() {
$container.mousemove(function(e) {
e.stopPropagation();
var mouseX = e.pageX;
var width = mouseX - limitLeft;
// if the mouse movements are confined to the container move on.
if ( mouseX < limitRight && mouseX > limitLeft ) {
// move the slider.
$slider.offset( {
left: mouseX
} );
// reveal or hide the background img.
$planeA.width( width );
}
});
}
} );
/*_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */