$(function () { imgratio() setTimeout(function () { imgratio(); }, 300) $(".ratio-img").each(function (index, element) { $(this).attr({ "src": $(this).data("src") }); }); var rtime = new Date(); var timeout = false; var delta = 200; $(window).resize(function () { rtime = new Date(); if (timeout === false) { timeout = true; setTimeout(resizeend, delta); } }); function resizeend() { if (new Date() - rtime < delta) { setTimeout(resizeend, delta); } else { timeout = false; imgratio()//ratio } } }) function imgratio() { $(".ratio-img").each(function (index, element) { if ($(this).is(":visible")) { //褰撳墠鍏冪礌鍙 $(this).css({ height: Math.floor($(this).width() * $(this).data("ratio")) });//Math.floor鍚戜笅鍙栨暣 } }); } var nullimg = '/images/null.gif'; function lod(t) { t.onerror = null; t.src = nullimg } $(function () { $(".ratio-img").each(function () { if ($(this).attr("src") == "") { $(this).attr({ "src": nullimg }) } }) })