小编Jes*_*ist的帖子

滚动然后修复

我已经尝试了互联网上我能找到的每一件事,因为我是js中的一个完整的菜鸟我正在尝试学习一些更复杂的css我不知道为什么这个滚动然后修复代码不起作用并且不要'我知道如何让它发挥作用.基本上我有一个标题包装,其中包括373px高度的header_pic和高度为50像素的header_nav.我只想滚动到header_nav的顶部,然后将其设置为固定位置,但我使用的每一个单独的工作由于某种原因而且我确实在我的html页面中包含了google的jQuery CDN头部区域,然后我包含了我的外部脚本.

以下是我在jsfiddle中的网页示例:https://jsfiddle.net/pyr2h0c5/

var elementPosition = $('#header_nav').offset();

$(window).scroll(function () {
    if ($(window).scrollTop() > elementPosition.top) {
        $('#header_nav').css('position', 'fixed').css('top', '0');
    } else {
       $('#header_nav').css('position', 'static');
    }
});
Run Code Online (Sandbox Code Playgroud)

谢谢你的好评:D

html javascript css jquery

1
推荐指数
1
解决办法
7317
查看次数

Belongs_to alias

I want to get the username of comment author like this

comment.commenter
Run Code Online (Sandbox Code Playgroud)

models/comment.rb

class Comment < ActiveRecord::Base
 belongs_to :commenter
 belongs_to :commentable, polymorphic: true
end
Run Code Online (Sandbox Code Playgroud)

models/user.rb

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

 validates :username, presence: true, uniqueness: true

 has_many :comments, as: :commenter
end
Run Code Online (Sandbox Code Playgroud)

When i try to create Comment directly to db using this line of code:

Comment.create(commentable_type: 'Pokemon', commentable_id: 1, content: …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails ruby-on-rails-4

1
推荐指数
1
解决办法
1105
查看次数

标签 统计

css ×1

html ×1

javascript ×1

jquery ×1

ruby-on-rails ×1

ruby-on-rails-4 ×1