$(function () { imgratio()//鍒濆鍖栧浘鐗噐atio setTimeout(function () { imgratio(); }, 200) $(".ratio-img").each(function (index, element) { $(this).attr({ "src": $(this).data("src") });//鍥剧墖棰勫姞杞 }); //绐楀彛鏀瑰彉澶у皬鍥炶皟ratio锛 var rtime = new Date(); var timeout = false; var delta = 200; $(window).resize(function () { rtime = new Date(); if (timeout === false) { timeout = true; setTimeout(resizeend, delta); //resize鍙洖璋冩渶鍚庝竴娆 } }); function resizeend() { //window.resize鍥炶皟 if (new Date() - rtime < delta) { setTimeout(resizeend, delta); } else { timeout = false; imgratio()//ratio } } // }) function imgratio() {//鍥剧墖 ratio鏂规硶璋冪敤 $(".ratio-img").each(function (index, element) { if ($(this).is(":visible")) { $(this).css({ height: Math.floor($(this).width() * $(this).data("ratio")) }); } }); } //鏃犲浘鍥惧儚 var nullimg = '../images/error.png'; function lod(t) { t.onerror = null; t.src = nullimg } $(function () { $(".ratio-img").each(function () { if ($(this).attr("src") == "") { $(this).attr({ "src": nullimg }) } }) })