一.延時加載圖片的方法
// 圖片延時加載 .wait_load是綁定在圖片上的class值
$('.wait_load').css('opacity','0');
// 當document滑動到當前位置時才顯示
function waitLoad(){
// 延時執(zhí)行
setTimeout(function(){
// 遍歷出所有的圖片
$('.wait_load').each(function(index){
if($(window).height() + $(document).scrollTop() >= $(this).offset().top){
// 將圖片的src設置成當前圖片的xsrc
$(this).attr('src',$(this).attr('xsrc')).animate({
'opacity':1
},1000);
}
});
},500);
}
//waitLoad();
// 滾動或者window改變,都調(diào)用waitLoad()方法
$(document).on('scroll',waitLoad);
$(window).on('resize',waitLoad);
二.三元運算符
var score = 61;
var result;
result = score > 60 ? '及格':'不及格';
//相當于
if(score > 60){
result = '及格'
}else{
result = '不及格'
}