$(document).ready(function(){ //create a new WebSocket object. var wsUri = "ws://"+location.hostname+":9000/prezentacja/server.php"; websocket = new WebSocket(wsUri); websocket.onopen = function(ev) { // connection is open alert("Połączono"); } var umsg; //Message Receved websocket.onmessage = function(ev) { console.log('Message '+ev.data); var msg = JSON.parse(ev.data); umsg = msg.message; console.log('wiadomosc: '+umsg); var arr = umsg.split(","); var img = document.getElementById("img-"+arr[0]); var widthpx = img.clientWidth; $( "#img-"+arr[0] ).animate({ opacity: 0, width: "0px" }, "slow", function() { console.log('img-'+arr[0]); document.getElementById("img-"+arr[0]).src="img/"+arr[1]+".png"; console.log('animate_complete'); $( "#img-"+arr[0] ).animate({ opacity: 1, width: widthpx+"px" }, "slow", function() { var glow = $('#nazwa-'+arr[0]); glow.addClass('glow'); glow.fadeOut(function() { glow.text(arr[2]); }).fadeIn(function(){glow.removeClass('glow');}); }); }); }; });