如何使用 ruby on Rails 控制弹出窗口,鼠标滚动
我有一个应用程序,用户可以在其中查看单元格列表。对于每个单元格,用户可以看到该单元格的两个图像作为弹出菜单。问题是,选择列表时会下载所有图像,这使得我的页面非常慢。 我希望仅当鼠标悬停在链接上时才下载图像。 有关信息:我正在使用 DOM 弹出工具包 链接文本
这里是主页并链接到弹出菜单
<div id="span_div">
<span id="cell_link_<%= @cell.cellid %>" class="popup_link" Popup.modal = true><%= @cell.cellname%>
<%= render :partial => 'cell_popup' %>
<%= javascript_tag "new Popup('cell_popup_#{@cell.cellid}','cell_link_#{@cell.cellid}')" %>
</span>
</div>
这里是细胞图像的一部分
<div id="cell_popup_<%= @cell.cellid %>" class="popup popup_draghandle" style="display:none">
<table width="418" border="0">
<tr>
<td width="201" align="center" valign="top">Raw</td>
<td width="201" align="center" valign="top">Repaired</td>
</tr>
<tr>
<td align="center" valign="top">
<% if @full_report == true then%>
<%raw_morph = @raw_morph.last%>
<img src="<%= url_for(:action => 'jpegfile', :controller => 'neuronviewer',:morph_id => raw_morph.morphologyid)%>" alt="" width="200" height="200"/>
<%end%>
</td>
<td align="center" valign="top">
<%if @repaired == true then%>
<%repaired_morph = @repaired_morph.last%>
<img src="<%= url_for(:action => 'jpegfile', :controller => 'neuronviewer', :morph_id => repaired_morph.morphologyid)%>" alt="" width="200" height="200"/>
</td>
</tr>
<%end%>
</table>
有人有任何想法吗?
I have an application where user can see a list of cells. For each cell the user can see two images of the cell as popup menu. The problem is that all images are downloaded when a list is selected and that makes my page very slow.
I would like that the image is downloaded only if mouse is rolled-over the link.
For information: I’m using DOM popup kit link text
Here the main page and link to popup menu
<div id="span_div">
<span id="cell_link_<%= @cell.cellid %>" class="popup_link" Popup.modal = true><%= @cell.cellname%>
<%= render :partial => 'cell_popup' %>
<%= javascript_tag "new Popup('cell_popup_#{@cell.cellid}','cell_link_#{@cell.cellid}')" %>
</span>
</div>
Here a partial for cell images
<div id="cell_popup_<%= @cell.cellid %>" class="popup popup_draghandle" style="display:none">
<table width="418" border="0">
<tr>
<td width="201" align="center" valign="top">Raw</td>
<td width="201" align="center" valign="top">Repaired</td>
</tr>
<tr>
<td align="center" valign="top">
<% if @full_report == true then%>
<%raw_morph = @raw_morph.last%>
<img src="<%= url_for(:action => 'jpegfile', :controller => 'neuronviewer',:morph_id => raw_morph.morphologyid)%>" alt="" width="200" height="200"/>
<%end%>
</td>
<td align="center" valign="top">
<%if @repaired == true then%>
<%repaired_morph = @repaired_morph.last%>
<img src="<%= url_for(:action => 'jpegfile', :controller => 'neuronviewer', :morph_id => repaired_morph.morphologyid)%>" alt="" width="200" height="200"/>
</td>
</tr>
<%end%>
</table>
Anyone have any idea to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本质上,这个想法是为您的跨度创建一个鼠标悬停操作,通过 AJAX 请求加载图像。我们将使用缓存变量来确保您不会在一页加载中多次发出相同的请求。
以下假设为原型。我没有时间测试它,所以不要指望一个完美的例子。
大部分工作是通过向跨度添加 on mouseover 属性来完成的。
现在清理一下:
将部分中除 div 之外的所有内容移至名为 cell 的视图。用通用的“获取图像”消息填补空白。
所以你的部分现在看起来像:
而你的名为 popup 的新视图看起来像:
现在剩下的就是将控制器连接到新视图并为 AJAX 做好准备。
添加响应单元控制器获取的弹出路由。
将操作添加到 CellsController
Essentially the idea is to create an on mouseover action for your span that loads the images with an AJAX request. We'll use a cache variable to ensure that you aren't making the same request multiple times in a for one page load.
The following assumes Prototype. I haven't time to test it, so don't expect a flawless example.
Most of the work is done by adding an on mouseover attribute to the span.
Now to clean things up:
Move everything in the partial but the div to a view called cell. Fill the void with a generic Fetching images message.
So your partial now looks like:
And your new view called popup looks like:
Now all that's left is to connect the controller to the new view and prepare it for AJAX.
Add a popup route responding to get for the cell controller.
Add the action to the CellsController