Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][CSS] Płynność animacji w różnych przeglądarkach
kamilo818
post
Post #1





Grupa: Zarejestrowani
Postów: 250
Pomógł: 11
Dołączył: 20.01.2014

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


Witam,
zmagam się z pewnym problemem.
Jestem w trakcie pisania strony : http://page4u.waw.pl/ania5/ i wszystkie aniamcje podczas scrolowania strony działają poprawnie. Dokładnie chodzi mi płynność przscrollowania strony (przechodzenie między slajdami).

Pod Firefoxem wszystko działa idealnie, niestety pod Google Chrome i IE 11 działa strasznie - brak płynności.

Ponież kod aniamacji :

  1. var $document = $(document);
  2. $document.ready(function(){
  3. //////////////////////////////////////////////**
  4. var winWidth, winHeight;
  5. var $body = $('body'),
  6. $circle = $('.circle');
  7. var R = $circle.width() / 2;
  8. var C = Math.PI * R * 2;
  9.  
  10. $(window).on('resize', function(){
  11.  
  12. winWidth = $(this).width();
  13. winHeight = $(this).height();
  14. $body.css('height', C + winHeight);
  15.  
  16. }).trigger('resize');
  17.  
  18. var scrolled = false;
  19.  
  20.  
  21. $document.on('scroll', function(){
  22.  
  23. var top = $document.scrollTop();
  24.  
  25. if(top > C - 1){
  26. $document.scrollTop(1);
  27. } else if (top == 0 && scrolled) {
  28. $document.scrollTop(C - 1);
  29. }
  30.  
  31. scrolled = true;
  32.  
  33. var d = ((top / C) * Math.PI * 2) - (Math.PI);
  34.  
  35. var x = Math.cos(d) * R;
  36. var y = Math.sin(d) * R;
  37.  
  38. $circle.css({
  39. top: -(R-y) + winHeight/2,
  40. left: -(R-x) + winWidth/2
  41. });
  42.  
  43. ////////ułożenie orbit
  44. $('div#orbita').each(function(){
  45. $(this).css({
  46. top: (-(R-y) + winHeight/2)+(($circle.height()-$(this).height())/2),
  47. left: (-(R-x) + winWidth/2)+(($circle.width()-$(this).width())/2)
  48. });
  49. });
  50.  
  51. }).trigger('scroll');
  52.  
  53. /////////////pozycja slajdów
  54.  
  55. var $things = $circle.children('div:not(.planet)').css('position', 'absolute');
  56. var i;
  57. $things.each(function(i){
  58.  
  59. var $this = $(this);
  60.  
  61. var a = (Math.PI * 2 / $things.length) * i;
  62.  
  63. var x = Math.cos(a) * R;
  64. var y = Math.sin(a) * R;
  65.  
  66. $this.css({
  67. top: y + R - ($this.height() / 2)-20,
  68. left: x + R - ($this.width() / 2)-20-(winWidth*0.05)
  69. });
  70.  
  71. });
  72.  
  73. ///////////////// pozycje planet
  74.  
  75. function setPos(pozycja, pozycja2, RR, $this){
  76.  
  77. var a = (Math.PI * 2 / pozycja) * pozycja2;
  78. var x = Math.cos(a) * RR;
  79. var y = Math.sin(a) * RR;
  80.  
  81. $this.css({
  82. top: y + RR - ($this.height() / 2),
  83. left: x + RR - ($this.width() / 2)
  84. });
  85.  
  86. setInterval(function(){
  87. if(pozycja2==pozycja){
  88. pozycja2=0;
  89. }
  90. a = (Math.PI * 2 / pozycja) * pozycja2++;
  91. x = Math.cos(a) * RR;
  92. y = Math.sin(a) * RR;
  93.  
  94. $this.css({
  95. top: y + RR - ($this.height() / 2),
  96. left: x + RR - ($this.width() / 2)
  97. });
  98.  
  99. }, Math.floor((Math.random() * 10) + 1));
  100.  
  101. }
  102.  
  103. var poz = 5000;
  104.  
  105.  
  106. var $thing = $('.b').children().css('position', 'absolute');
  107. $thing.each(function(){
  108. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.b').width()/2), $thing);
  109. });
  110.  
  111. var $thing = $('.c').children().css('position', 'absolute');
  112. $thing.each(function(){
  113. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.c').width()/2), $thing);
  114. });
  115.  
  116. var $thing = $('.circle').children('.planet').css('position', 'absolute');
  117. $thing.each(function(){
  118. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.circle').width()/2), $thing);
  119. });
  120.  
  121. var $thing = $('.d').children().css('position', 'absolute');
  122. $thing.each(function(){
  123. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.d').width()/2), $thing);
  124. });
  125.  
  126. var $thing = $('.e').children().css('position', 'absolute');
  127. $thing.each(function(){
  128. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.e').width()/2), $thing);
  129. });
  130.  
  131. var $thing = $('.f').children().css('position', 'absolute');
  132. $thing.each(function(){
  133. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.f').width()/2), $thing);
  134. });
  135.  
  136. var $thing = $('.g').children().css('position', 'absolute');
  137. $thing.each(function(){
  138. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.g').width()/2), $thing);
  139. });
  140.  
  141. var $thing = $('.h').children().css('position', 'absolute');
  142. $thing.each(function(){
  143. setPos(poz,Math.floor((Math.random() * poz) + 0), ($('.h').width()/2), $thing);
  144. });
  145.  
  146. /////////////////
  147.  
  148. $(window).bind('resize', function(e){
  149. window.resizeEvt;
  150. $(window).resize(function()
  151. {
  152. clearTimeout(window.resizeEvt);
  153. window.resizeEvt = setTimeout(function()
  154. {
  155.  
  156. location.reload();
  157.  
  158. }, 250);
  159. });
  160. });
  161. //////////////////////////////////////////////**
  162. ///////////// obsluga menu
  163. $('.menu #menu span:first-child').css({
  164. 'font-size':'16px',
  165. 'font-weight':'bold'
  166. });
  167.  
  168. $('.menu #menu span').click(function(){
  169. if(open_menu){
  170. $(".menu").css({'right': "-170px"});
  171. open_menu=false;
  172. }
  173. $('.menu #menu span').css({
  174. 'font-size':'',
  175. 'font-weight':''
  176. });
  177. $(this).css({
  178. 'font-size':'16px',
  179. 'font-weight':'bold'
  180. });
  181. var id = $(this).attr('pos');
  182. $('html, body').stop().animate({
  183. scrollTop: id
  184. }, 1000);
  185. });
  186.  
  187. var start = [];
  188. var end =[];
  189. var arrow_pos=0;
  190. $('div.menu #menu span').each(function(i){
  191.  
  192. start[i] = $(this).attr('pos');
  193. end[i] = $(this).next('span').attr('pos');
  194. if(!end[i]){
  195. end[i] = $('body').height();
  196. }
  197.  
  198. $document.on('scroll', function(){
  199.  
  200. if($(this).scrollTop()>=start[i] && $(this).scrollTop()<end[i]){
  201. $('.menu #menu span:nth-child('+(i+1)+')').css({
  202. 'font-size':'16px',
  203. 'font-weight':'bold'
  204. });
  205. arrow_pos=i;
  206. }else{
  207. $('.menu #menu span:nth-child('+(i+1)+')').css({
  208. 'font-size':'',
  209. 'font-weight':''
  210. });
  211. }
  212. });
  213.  
  214. });
  215.  
  216. var open_menu=false;
  217. $('.menu .mobile_menu').click(function () {
  218. if(!open_menu){
  219. $(".menu").css({'right': "-0px"});
  220. open_menu=true;
  221.  
  222. }else{
  223. $(".menu").css({'right': "-170px"});
  224. open_menu=false;
  225. }
  226.  
  227. });
  228.  
  229. $(document).keydown(function(e) {
  230.  
  231. if(e.keyCode == 40 || e.keyCode){
  232. $('html, body').stop().animate({
  233. scrollTop: start[arrow_pos+1]
  234. }, 500);
  235. }
  236.  
  237. if(e.keyCode == 38 || e.keyCode == 37){
  238. $('html, body').stop().animate({
  239. scrollTop: start[arrow_pos-1]
  240. }, 500);
  241. }
  242.  
  243.  
  244. });
  245.  
  246. var arrow_keys_handler = function(e) {
  247. switch(e.keyCode){
  248. case 37: case 39: case 38: case 40: // Arrow keys
  249. case 32: e.preventDefault(); break; // Space
  250. default: break; // do not block other keys
  251. }
  252. };
  253. window.addEventListener("keydown", arrow_keys_handler, false);
  254.  
  255. });
  256. ////////////////////////


Będę wdzieczy za pomoc.

Ktoś coś smile.gif?
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 20.08.2025 - 05:14