简体   繁体   English

Rails 4 jQuery高亮效果未执行

[英]Rails 4 jquery highlight effect not executing

I'm trying to highlight changes in my posts index page where the form is also displayed and submit(both on same page). 我正在尝试在帖子索引页面中突出显示所做的更改,在该页面中还显示并提交了表单(都在同一页面上)。 I'd like to slide and highlight the new post. 我想滑动并突出显示新帖子。 to know if post==new I put current_item in my controller: 知道post == new我是否将current_item放在控制器中:

respond_to do |format|  
      if @post.save
        format.html { redirect_to posts_path, notice: '<i class="fa fa-check fa-5x"></i>'.html_safe }
        format.js   { @current_item = @post } #use this in vew to check if post is newly added
        format.json { render action: 'index', status: :created, location: @post }

      else
        format.html { render action: 'new' }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end

index.html.erb: index.html.erb:

<% if post == @current_item %>
            <div id="current_item">
              <% end %>

     ..........more code......

 <% if post == @current_item %>
            </div>
              <% end %>

my js 我的js

 $(function() {
  $('#current_item').effect('highlight', {}, 3000)
   });

nothing happens, and I'm also trying to do the slide down effect on that div as well bu want to get the highlight working first. 什么也没发生,我也正在尝试对该div进行滑落效果,同时bu希望首先使突出显示起作用。

I tried doing it with css with no success. 我尝试用css进行操作,但没有成功。 it highlights everything. 它突出了一切。

This effect is not part of the core jQuery library. 这种效果不是核心jQuery库的一部分。 It is part of jQuery UI library. 它是jQuery UI库的一部分。 Did you include that in your project? 您在项目中包括了吗? Source: api.jqueryui.com/highlight-effect 资料来源: api.jqueryui.com/highlight-effect

Here is a working example: 这是一个工作示例:

$(function() 
{
    $('#current_item').effect('highlight', {}, 3000)
});

http://jsfiddle.net/s8ubK/ http://jsfiddle.net/s8ubK/

So, I guess you forgot to include the jQuery UI library in your project. 因此,我想您忘记了在项目中包含jQuery UI库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM