阻止每个rails 3.1和jQuery [英] block each rails 3.1 and jquery

查看:77
本文介绍了阻止每个rails 3.1和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码对网页中的每个图像进行机械化处理:

I get with Mechanize a array with every images from a web page with this code:

url = http://www.cnn.com
page = Mechanize.new.get(url)
@images_urls = page.images.map{|img| img.url.to_s }.compact

在我的视野中,该图像带有一个块:

and I get in my view this images with a block:

<div class="preview">
<% @images_urls.each do |image_url| %>
 <%=  image_tag "#{image_url}" %>
<% end %>
</div>

此数组生成网址,例如:

This array generate urls like e.g.:

<img src="http://i2.cdn.turner.com/cnn/dam/assets/120226120954-mandela-paper-t1-main.jpg" alt="120226120954-mandela-paper-t1-main">
<img src="http://i2.cdn.turner.com/cnn/dam/assets/120226120954-mandela-paper-t1-main.jpg" alt="120226120954-mandela-paper-t1-main">
<img src="http://i.cdn.turner.com/cnn/.e/img/3.0/global/icons/video_icon.gif" alt="Video_icon">
.
.
.

我需要一个代码来删除高度和宽度小于50像素的图像,然后我得到

I need a code for remove images less 50px in height and width, then I get

$('.preview img').load(function() {
   var $img = $(this);
   alert ($img.width());
   if ($img.height() < 50 || $img.width() < 50) {
       $img.remove();
   }  
});

我进入每个图像的警报($ img.width()) 0 ...因此,请针对这种情况删除所有图像.

I get in alert ($img.width()); the value 0 for every images...So remove every images for this condition.

图像的值大于零0 !!

为什么?

问题是我正在使用Fancybox,并且代码在Fancybox回调之后

The problem is that I'm using Fancybox and the code goes after Fancybox callback

onComplete

谢谢Rob W

推荐答案

尝试使用此代码段确定是否已加载图像,

Try this snippet for determine if the image was loaded, Here ..

这篇关于阻止每个rails 3.1和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆