Код работает через раз
Добрый день.
Не могу несколько дней разобраться с одним кодом, работает но почему то через раз (на первом изображение работает, на втором нет, на третьем работает на четвертом нет и т.д.). Чуток JS знаю, но не очень, может хоть ткните в какую сторону смотреть. Сам код. $(document).ready(function () { var inProgress = false; var startFrom = 20; $(window).scroll(function () { if ($(window).scrollTop() + $(window).height() >= $(document).height() - 500 && !inProgress) { $.ajax({ url: 'load.php', method: 'POST', data: { "startFrom": startFrom }, beforeSend: function () { inProgress = true; } }).done(function (data) { data = jQuery.parseJSON(data); if (data.length > 0) { if (data.length == 10) { $("#articles").append("<div class=\"row\"><div class=\"col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1\"><div class=\"content_res\"><ins class=\"adsbygoogle google_ads\" style=\"display:block\" data-ad-client=\"ca-pub-2928478915116205\" data-ad-slot=\"1371563414\" data-ad-format=\"auto\"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});<\/script></div></div></div>"); } $.each(data, function (index, data) { var top_text_res = "<div class=\"row border_top_text_res\"><a class=\"a_href_id\" href=\"story.php?" + data.id + "\">гифка №" + data.id + " </a><div class=\"date_res\">" + data.date_res + "</div></div>"; var main_text_res = "<h2>" + data.description + "</h2><div class=\"gif-with-play\"><img src=\"" + data.text_res + "\" class=\"img-responsive\" alt=\"" + data.description + "\" data-srcgif=\"" + data.text_res_gif + "\"></div>"; (function ($) { $('.gif-with-play').on('click', function () { var $this = $(this), $img = $this.children('img'), $imgSrc = $img.attr('src'), $imgSrcgif = $img.attr('data-srcgif'), $imgExt = $imgSrcgif.split('.'); if ($imgExt[1] === 'gif') { $this.addClass('loading-hide'); $img.attr('src', $img.data('srcgif')).attr('data-srcgif', $imgSrc); $($img).load(function () { $this.removeClass('loading-hide'); }); } else { $img.attr('src', $imgSrcgif).attr('data-srcgif', $img.data('srcgif')); } $this.toggleClass('play'); }); })(jQuery); var bot_text_res = "<div class=\"row border_bottom_text_res\"><div class=\"up col-lg-1 col-md-1 col-sm-1 col-xs-1\"><div class=\"vote2\"><a href=\"\" class=\"vote\" id=\"" + data.id + "\" name=\"up\"><div class=\"glyphicon glyphicon-plus\"></div></a></div></div><div id=\"vote" + data.id + "\" class=\"vote2 col-lg-1 col-md-1 col-sm-1 col-xs-1\">" + data.diff_res + "</div><div class=\"down col-lg-1 col-md-1 col-sm-1 col-xs-1\"><div class=\"vote2\"><a href=\"\" class=\"vote\" id=\"" + data.id + "\" name=\"down\"><div class=\"glyphicon glyphicon-minus\"></div></a></div></div><script src=\"js/votes.js\"><\/script><div class=\"share_res\"><script src=\"//yastatic.net/es5-shims/0.0.2/es5-shims.min.js\"><\/script><script src=\"//yastatic.net/share2/share.js\"><\/script><div class=\"ya-share2 visible-xs visible-sm\" data-title=\"гифка №" + data.id + "\" data-url=\"http://gifs.reseto.com/story.php?" + data.id + "\" data-image=\"http://gifs.reseto.com/" + data.text_res + "\" data-services=\"vkontakte,facebook,gplus,twitter,viber,whatsapp\"></div><div class=\"ya-share2 hidden-xs hidden-sm\" data-title=\"гифка №" + data.id + "\" data-url=\"http://gifs.reseto.com/story.php?" + data.id + "\" data-image=\"http://gifs.reseto.com/" + data.text_res + "\" data-services=\"vkontakte,facebook,gplus,twitter\"></div></div></div>"; $("#articles").append("<div class=\"row\"><div class=\"col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1\"><div class=\"content_res\">" + top_text_res + main_text_res + bot_text_res + "</div></div></div>"); }); inProgress = false; startFrom += 10; } }); } }); }); |
Часовой пояс GMT +3, время: 20:35. |