Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CSS][JavaScript] Losowanie liczby (animacja)
mfernal010
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 22.06.2015

Ostrzeżenie: (0%)
-----


Witam wszystkich Serdecznie.

Znalazłem na forum skrypt: Temat: innePHPLosowe wyswietlanie obrazkow

Przerobiłem go pod siebie lecz mam problem mianowicie chciałbym, aby losowanie nie było od prawej do lewej lecz od góry do dołu lub na odwrót. (IMG:style_emoticons/default/facepalmxd.gif)

Aktualnie mój kod wygląda tak:
  1. <meta charset="utf-8">
  2. <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  3. <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700' rel='stylesheet' type='text/css'>
  4.  
  5. <script src="howler.js"></script>
  6.  
  7.  
  8.  
  9.  
  10.  
  11. #wrapper { position: absolute; top: 22px; width: 100px; height: 720px; overflow: hidden;
  12.  
  13. }
  14. ul {list-style-type: none; margin: 0px; padding: 1px; width: 100%; }
  15. li {list-style-type: none; float: left; width: 90px; height: 90px; margin: 5px;
  16. background: url(images/los.png); text-align: center;
  17. line-height: 75px;
  18. font-size: 25px;
  19. color: #8f8f8f;
  20. font-family: 'Ubuntu', sans-serif;
  21. font-weight: 400; position: relative; left: 0px; }
  22. #result {width: 100px; height: 100px;}
  23.  
  24. #button{
  25. position: absolute;
  26. left: 250px;
  27. background: url(images/button.png);
  28. width: 199px; height: 45px;
  29. border: 0px;
  30. color: #ffffff;
  31. font-size: 17px;
  32. font-family: 'Ubuntu', sans-serif;
  33. font-weight: 400;
  34.  
  35. }
  36. </style>
  37. </head>
  38.  
  39. <div id="ramka">
  40.  
  41. <div id="wrapper">
  42. <ul>
  43. <li>1</li>
  44. <li>2</li>
  45. <li>3</li>
  46. <li>4</li>
  47. <li>5</li>
  48. <li>6</li>
  49. <li>7</li>
  50. <li>8</li>
  51. <li>9</li>
  52. <li>10</li>
  53. </ul>
  54.  
  55. </div>
  56. </div> <div id="strzalka"></div>
  57. <br>
  58. <button id="button" >Rozpocznij losowanie</button><br/><br/><br/><br/>
  59.  
  60.  
  61. $(document).ready(function(){
  62. $("ul > li:lt(5)").clone().appendTo("ul")
  63. $("ul").css({height: ($("ul > li").length * 100)})
  64. $("#button").click(function(){
  65. if($(this).text()==="Rozpocznij losowanie"){
  66. stop = false
  67. $(this).text("Zatrzymaj losowanie");
  68. $("#result").empty();
  69. $("#textDiv").empty();
  70. scroll()
  71. }
  72. else {
  73. stop = true
  74. $(this).text("Rozpocznij losowanie");
  75.  
  76. }
  77. });
  78. });
  79. var stop = false;
  80. var speed = 40
  81. function scroll() {
  82. count = parseInt($("ul > li").first().css("left"))
  83. if(count < 0){ count = count / -100;}
  84. if(stop){show(count); return false;}
  85. if(count === ($("ul > li").length - 10)){count =0; $("ul > li").css({left: "0px"});}
  86.  
  87. $("ul > li").slice(1).animate({left:"-"+((count+1)*100)+"px"}, speed, "linear");
  88. $("ul > li").first().animate({left:"-"+((count+1)*100)+"px"}, speed, "linear", function(){scroll();} );
  89. }
  90. function show(count){
  91. count = count + 3;
  92. $("ul > li").slice(count,(count+1)).clone().css({left: "0px"}).appendTo("#result");
  93.  
  94.  
  95. }
  96.  
  97.  
  98.  
  99.  
  100. </script>
  101. <div id="result"></div>
  102.  
  103.  
  104.  
  105.  
  106.  
  107. </body>
  108. </html>
  109.  


Czy znalazłby się ktoś dobry i pomógł mi zrobić to, aby losowanie było od góry w dół (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/sadsmiley02.gif)
Go to the top of the page
+Quote Post
rad11
post
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


A probowales w animacji kombinacji zmiany z left na np top lub bottom?oraz funkcji random?
http://www.w3schools.com/jsref/jsref_random.asp

Ten post edytował rad11 22.06.2015, 13:19:22
Go to the top of the page
+Quote Post
fate
post
Post #3





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


http://jsfiddle.net/1sqvpb94/1/
Go to the top of the page
+Quote Post
mfernal010
post
Post #4





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 22.06.2015

Ostrzeżenie: (0%)
-----


Cytat(fate @ 22.06.2015, 14:19:23 ) *

Super dzięki (IMG:style_emoticons/default/arrowheadsmiley.png) , nie pomyślałem o tym by zrobić transform.

Mam pytanie jeszcze ponieważ teraz borykam się z problemem drugim.
Chce wysłać daną liczbę do skryptu PHP.

Używam aktualnie tak:
  1. var hr = new XMLHttpRequest();
  2. var url = "zapisz.php";
  3. var vars = "pierwszy=" +(count+2)+ "&drugi=test";
  4. hr.open("POST", url, true);
  5. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  6. hr.onreadystatechange = function() {
  7. console.log(hr);
  8.  
  9. if(hr.readyState == 4 && hr.status == 200) {
  10. var return_data = hr.responseText;
  11. document.getElementById("status").innerHTML = return_data;
  12. }
  13. }
  14.  
  15. hr.send(vars);
  16. document.getElementById("status").innerHTML = "processing...";
  17.  
  18. }


Lecz chodzi mi o to, aby było wszystko wysyłane przykładowo:
  1. <div id="result"><li style="left: 0px;">6</li></div>

lub też tylko dana wylosowana liczba.

Nie pomoże mi nikt (IMG:style_emoticons/default/questionmark.gif) (IMG:style_emoticons/default/mellow.gif)

Ten post edytował mfernal010 25.06.2015, 20:29:28
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 02:15