10 / 9 / 5
Регистрация: 17.02.2016
Сообщений: 351
1

Не могу разобраться в JS, а нужно лишь немного подредактировать падение снега

15.09.2016, 23:59. Показов 717. Ответов 7
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Имеется вот такой JS код, который отображает падение снега на сайте, дело в том что мне нужно падение конфетти, а не снега, сами снежинки я переделал, но получается так что конфетти падает только одного цвета и размера, как сделать что бы можно было прикрепить несколько вариантов png файлов.
Плохо разбираюсь в этом, метод тыка не к чему хорошему не привел .
Javascript
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<div onclick="stopsnow()" id="snow-start">Выкл. снег</div>
<script type="text/javascript"> 
  var snowsrc="http://all-blogspot.com/blog/img/snow.png";
  var no = 20; 
  var log = 0;
  var hidesnowtime = 0;
  var snowdistance = "windowheight";
 
  var ie4up = (document.all) ? 1 : 0;
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
 
    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
 
  var dx, xp, yp;    
  var am, stx, sty;  
  var i, doc_width = 800, doc_height = 600; 
 
  if (ns6up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
  } else if (ie4up) {
    doc_width = iecompattest().clientWidth;
    doc_height = iecompattest().clientHeight;
  }
 
  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();
  snowsrc=(snowsrc.indexOf("all-blogspot.com")!= 1)? "http://all-blogspot.com/blog/img/snow.png" : snowsrc
  for (i = 0; i < no; ++ i) {  
    dx[i] = 0;                        
    xp[i] = Math.random()*(doc_width-50); 
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;      
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();   
        if (ie4up||ns6up) {
      if (i == 0) {
        document.write("<div id="dot"+ i +"" style="POSITION: fixed; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src='"+snowsrc+"' border="0"><\/div>");
      } else {
        document.write("<div id="dot"+ i +"" style="POSITION: fixed; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src='"+snowsrc+"' border="0"><\/div>");
      }
    }
  }
 
  function snowIE_NS6() {  
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
        doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (i = 0; i < no; ++ i) { 
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
      }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
    }
    snowtimer=setTimeout("snowIE_NS6()", 10);
  }
 
    function hidesnow(){
        if (window.snowtimer) clearTimeout(snowtimer)
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
    }
 
if (ie4up||ns6up){
    snowIE_NS6();
        if (hidesnowtime>0)
        setTimeout("hidesnow()", hidesnowtime*1000);
        }
 function stopsnow(){
 if (log==0){
  for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
  no = 0;
  log = 1;
  document.getElementById('snow-start').innerHTML ='Вкл. снег';
  }
  else { log = 0; no = 20; for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="visible";
 document.getElementById('snow-start').innerHTML ='Выкл. снег';
 
  }
 
 }
</script>
<a id="copy" href="http://all-blogspot.com/"></a>
<style>
#snow-start{
background: rgba(27, 25, 25, 0.4);
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
cursor: pointer;
line-height: 25px;
position: fixed;
right: 0px;
top: 0px;
border-radius: 0px 0px 0px 9px;
}
#copy{
color: rgba(20, 16, 16, 0);
font-size: 7px;
position: fixed;
text-decoration: none;
top: 24px;
right: 2px;
}
</style>
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
15.09.2016, 23:59
Ответы с готовыми решениями:

Синонимайзер. Часть вторая. Нужно немного подредактировать
Неделю назад разбирались с этой чудесной вещью тут...

Падение снега
как написать программу, реализующую выпадение снега - чтобы на верхней строке появлялось некое...

помогите с юнитом crt (падение снега)
написал прогу (падение снега) я на Паскале, используя unit crt; работает всё правильно на одном...

Немного нужно разобраться в программе
#include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;string.h&gt; int main() { const char delim =...

7
60 / 60 / 31
Регистрация: 24.05.2016
Сообщений: 202
16.09.2016, 03:06 2
Fruit, самый примитивный вариант - создать массив с изображениями и брать оттуда рандомную картинку.
1
10 / 9 / 5
Регистрация: 17.02.2016
Сообщений: 351
16.09.2016, 10:02  [ТС] 3
nekosoku, Дак я знаю это, но не знаю как это реализовать ...
0
60 / 60 / 31
Регистрация: 24.05.2016
Сообщений: 202
16.09.2016, 15:58 4
Fruit, попробуйте этот код:
Кликните здесь для просмотра всего текста
Javascript
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<div onclick="stopsnow()" id="snow-start">Выкл. снег</div>
<script type="text/javascript"> 
  var snowsrc="http://all-blogspot.com/blog/img/";
  var snowsrcs = ['snow.png','confetti.png', 'rain.png'];
  var no = 20; 
  var log = 0;
  var hidesnowtime = 0;
  var snowdistance = "windowheight";
 
  var ie4up = (document.all) ? 1 : 0;
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
 
    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
 
  var dx, xp, yp;    
  var am, stx, sty;  
  var i, doc_width = 800, doc_height = 600; 
 
  if (ns6up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
  } else if (ie4up) {
    doc_width = iecompattest().clientWidth;
    doc_height = iecompattest().clientHeight;
  }
 
  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();
  //snowsrc=(snowsrc.indexOf("all-blogspot.com")!= 1)? "http://all-blogspot.com/blog/img/snow.png" : snowsrc
  for (i = 0; i < no; ++ i) {  
    dx[i] = 0;                        
    xp[i] = Math.random()*(doc_width-50); 
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;      
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();   
        if (ie4up||ns6up) {
      if (i == 0) {
        document.write("<div id="dot"+ i +"" style="POSITION: fixed; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src='"+snowsrc+snowsrcs[Math.floor(Math.random()*(snowsrcs.length))]"' border="0"><\/div>");
      } else {
        document.write("<div id="dot"+ i +"" style="POSITION: fixed; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src='"+snowsrc+snowsrcs[Math.floor(Math.random()*(snowsrcs.length))]"' border="0"><\/div>");
      }
    }
  }
 
  function snowIE_NS6() {  
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
        doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (i = 0; i < no; ++ i) { 
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
      }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
    }
    snowtimer=setTimeout("snowIE_NS6()", 10);
  }
 
    function hidesnow(){
        if (window.snowtimer) clearTimeout(snowtimer)
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
    }
 
if (ie4up||ns6up){
    snowIE_NS6();
        if (hidesnowtime>0)
        setTimeout("hidesnow()", hidesnowtime*1000);
        }
 function stopsnow(){
 if (log==0){
  for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
  no = 0;
  log = 1;
  document.getElementById('snow-start').innerHTML ='Вкл. снег';
  }
  else { log = 0; no = 20; for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="visible";
 document.getElementById('snow-start').innerHTML ='Выкл. снег';
 
  }
 
 }
</script>
<a id="copy" href="http://all-blogspot.com/"></a>
<style>
#snow-start{
background: rgba(27, 25, 25, 0.4);
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
cursor: pointer;
line-height: 25px;
position: fixed;
right: 0px;
top: 0px;
border-radius: 0px 0px 0px 9px;
}
#copy{
color: rgba(20, 16, 16, 0);
font-size: 7px;
position: fixed;
text-decoration: none;
top: 24px;
right: 2px;
}
</style>
0
10 / 9 / 5
Регистрация: 17.02.2016
Сообщений: 351
16.09.2016, 16:17  [ТС] 5
nekosoku, Вообще не работает ...

Добавлено через 4 минуты
codepen.io
0
60 / 60 / 31
Регистрация: 24.05.2016
Сообщений: 202
16.09.2016, 16:26 6
Fruit,
Кликните здесь для просмотра всего текста
Javascript
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<div onclick="stopsnow()" id="snow-start">Выкл. снег</div>
<script type="text/javascript"> 
  var snowsrc="http://all-blogspot.com/blog/img/";
  var snowsrcs = ['snow.png','confetti.png', 'rain.png'];
  var no = 20; 
  var log = 0;
  var hidesnowtime = 0;
  var snowdistance = "windowheight";
 
  var ie4up = (document.all) ? 1 : 0;
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
 
    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
 
  var dx, xp, yp;    
  var am, stx, sty;  
  var i, doc_width = 800, doc_height = 600; 
 
  if (ns6up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
  } else if (ie4up) {
    doc_width = iecompattest().clientWidth;
    doc_height = iecompattest().clientHeight;
  }
 
  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();
  //snowsrc=(snowsrc.indexOf("all-blogspot.com")!= 1)? "http://all-blogspot.com/blog/img/snow.png" : snowsrc
  for (i = 0; i < no; ++ i) {  
    dx[i] = 0;                        
    xp[i] = Math.random()*(doc_width-50); 
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;      
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.7 + Math.random();   
        if (ie4up||ns6up) {
      if (i == 0) {
        document.write("<div id='dot'"+ i +" style='POSITION: fixed; Z-INDEX: '"+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;'><img src='"+snowsrc+snowsrcs[Math.floor(Math.random()*(snowsrcs.length))]+"' border='0'></div>");
      } else {
        document.write("<div id='dot'"+ i +" style='POSITION: fixed; Z-INDEX: '"+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;'><img src='"+snowsrc+snowsrcs[Math.floor(Math.random()*(snowsrcs.length))]+"' border='0'></div>");
      }
    }
  }
 
  function snowIE_NS6() {  
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
        doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (i = 0; i < no; ++ i) { 
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
      }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
    }
    snowtimer=setTimeout("snowIE_NS6()", 10);
  }
 
    function hidesnow(){
        if (window.snowtimer) clearTimeout(snowtimer)
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
    }
 
if (ie4up||ns6up){
    snowIE_NS6();
        if (hidesnowtime>0)
        setTimeout("hidesnow()", hidesnowtime*1000);
        }
 function stopsnow(){
 if (log==0){
  for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
  no = 0;
  log = 1;
  document.getElementById('snow-start').innerHTML ='Вкл. снег';
  }
  else { log = 0; no = 20; for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="visible";
 document.getElementById('snow-start').innerHTML ='Выкл. снег';
 
  }
 
 }
</script>
<a id="copy" href="http://all-blogspot.com/"></a>
<style>
#snow-start{
background: rgba(27, 25, 25, 0.4);
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
cursor: pointer;
line-height: 25px;
position: fixed;
right: 0px;
top: 0px;
border-radius: 0px 0px 0px 9px;
}
#copy{
color: rgba(20, 16, 16, 0);
font-size: 7px;
position: fixed;
text-decoration: none;
top: 24px;
right: 2px;
}
</style>
0
10 / 9 / 5
Регистрация: 17.02.2016
Сообщений: 351
16.09.2016, 17:16  [ТС] 7
nekosoku, Перестали падать ...

Добавлено через 45 минут
снежинки
0
10 / 9 / 5
Регистрация: 17.02.2016
Сообщений: 351
21.09.2016, 14:43  [ТС] 8
Помогите плиииз

Добавлено через 1 час 5 минут
Можно закрывать тему. Вопрос решён.
0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
21.09.2016, 14:43
Помогаю со студенческими работами здесь

Массив,немного подредактировать надо
Привет всем! В процедуре тут подсчитывается количество четных элементов,а надо,чтоб подсчитывал...

Есть простенький калькулятор. Требуется немного подредактировать окно ввода
После вывода результата в моем калькуляторе, требуется, чтобы цифры, вводимые пользователем,...

Нужно разобраться в программе, Не могу скомпилировать
Скажу честно - заказал программу, для сдачи в вузе. Теперь не могу в ней разобраться. Как её...

не могу разобраться никак. ОЧЕНЬ СРОЧНО НУЖНО!
нужно найти максимальную цифру из текущей даты и затем вывести максимальную @echo off set i=0...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
8
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru