我有一个占位符背景图片,我想在 之后将其替换为。
$.get("BIG-IMAGE-URL").done(function(data){
$('.MY-DIV-CLASS').css('background-image', 'url("BIG-IMAGE-URL")');
});
有谁知道如何制作这样一个简单的功能?
答案 0 :(得分:0)
您可以使用javascript加载大图像,并在加载事件处理程序中设置CSS背景。
public class NewsAdapter extends FirebaseListAdapter<News> {
public NewsAdapter(Activity activity, Class<News> modelClass, int modelLayout, Query ref) {
super(activity, modelClass, modelLayout, ref);
}
@Override
protected void populateView(View view, final News news, int i) {
final Context context = view.getContext();
final String title = news.getTitle();
final String photoUrl = news.getPhotoUrl();
// Create views and assign values
ImageView ivPhoto = (ImageView) view.findViewById(R.id.iv_news_photo);
if (photoUrl != null)
// Load the image using Glide
Glide.with(context)
.load(photoUrl)
.into(ivPhoto);
TextView tvTitle = (TextView) view.findViewById(R.id.tv_news_title);
tvTitle.setText(title)
}
}
此外,这是使用jQuery How can I check if a background image is loaded?
的类似解决方案