Skip to content

Commit edc7904

Browse files
mobile-adaptation of darkness-mode
1 parent 42edfdb commit edc7904

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

index.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ document.addEventListener("DOMContentLoaded", function(event) {
1212
document.querySelector('header h1').innerHTML = randomize;
1313
});
1414

15-
document.querySelector(".button_icon").addEventListener("click", function(){
16-
document.querySelector("header").classList.toggle("open_icon_menu");
15+
document.querySelector('.button_icon').addEventListener('click', function(){
16+
document.querySelector('header').classList.toggle('open_icon_menu');
1717
})
1818

19-
var gallery = document.querySelectorAll(".photo");
19+
var gallery = document.querySelectorAll('.photo');
2020

2121
for(var i = 0; i < gallery.length; i++) {
2222
(function loop(index) {
@@ -28,17 +28,24 @@ for(var i = 0; i < gallery.length; i++) {
2828

2929
$(function(){
3030
$('.fclick').on('click', darkness);
31-
$('body').mousemove(light_move);
32-
document.querySelector("body").addEventListener("touchmove", light_move);
31+
$('body').on('mousemove', light_move);
32+
$('body').on('touchmove', light_move_mobile);
3333
})
3434

3535
function light_move(e){
3636
if($('.fclick').text() == "Включить свет"){
37-
obj = document.getElementById("overlay");
37+
obj = document.getElementById('overlay');
3838
obj.style.top = e.clientY / document.documentElement.clientHeight * 100 - 150 + "vh";
3939
obj.style.left = 1 * e.clientX / document.documentElement.clientWidth * 100 - 150 + "vw";
4040
}
4141
}
42+
function light_move_mobile(e){
43+
if($('.fclick').text() == "Включить свет"){
44+
obj = document.getElementById('overlay');
45+
obj.style.top = e.targetTouches[0].clientY / document.documentElement.clientHeight * 100 - 150 + "vh";
46+
obj.style.left = 1 * e.targetTouches[0].clientX / document.documentElement.clientWidth * 100 - 150 + "vw";
47+
}
48+
}
4249
function darkness(){
4350
if($('.fclick').text() == "Выключить свет"){
4451
$('body').append("<div id='overlay' class='overlay'></div>");
@@ -48,7 +55,7 @@ function darkness(){
4855
'top': '-100vh',
4956
'left': '-100vw',
5057
'background-color': 'black',
51-
'background': 'radial-gradient(transparent,rgba(0,0,0,0.6),rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6))',
58+
'background': 'radial-gradient(circle, transparent,rgba(0,0,0,0.6),rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6), rgba(0,0,0,0.6))',
5259
'width': '300vw',
5360
'height': '300vh',
5461
'z-index': 5000,

0 commit comments

Comments
 (0)