查看我的 jsFiddle 看看发生了什么:http://jsfiddle.net/Amp3rsand/EDWHX/2/
如果您取消注释文章中的第二个 .content div,您将看到页脚像它应该隐藏的那样隐藏,然后在您到达页面底部时取消隐藏。我的麻烦是,当内容比视口(viewport)短时,我希望它显示页脚,就像第二个 .content div 被注释掉时一样。
(即 window.height > document.height 对吗?)
在我实际的网站上,.content div 被不同的 div 替换,每个页面都有唯一的 id,所以我不知道如何专门定位它们。我正在做的事情是正确的做法吗?
这是我为那些出于某种原因不想使用 jsFiddle 的人编写的代码:
HTML
<article>
<div class="content"></div>
<!--
<div class="content"></div>
-->
</article>
<footer>
<ul id="footerlinks">
<li><a href="#">home</a></li>
<li><a href="#">contact</a></li>
</ul>
</footer>
<div id="underfooter"></div>
CSS
article {
min-height: 500px;
background: black;
padding: 10px;
margin-bottom: 50px;
}
.content {
height:500px;
background: lightgrey;
border: 1px dashed red;
}
footer {
position: fixed;
bottom: -50px;
height: 40px;
width: 100%;
margin: 0 auto;
text-align: center;
border-top:2px solid #6ce6d5;
background: white;
z-index: 100;
}
#underfooter {
position: fixed;
bottom: -44px;
background: blue;
width: 100%;
height: 40px;
z-index: 90;
}
JQuery
$(function(){
$('footer').data('size','hide');
});
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() >= $(document).height() - 0)
{
if($('footer').data('size') == 'hide')
{
$('footer').data('size','show');
$('footer').stop().animate({
bottom:'0px'
},400);
$('#white2').stop().animate({
bottom:'6px'
},400);
}
}
else
{
if($('footer').data('size') == 'show')
{
$('footer').data('size','hide');
$('footer').stop().animate({
bottom:'-50px'
},400);
$('#white2').stop().animate({
bottom:'-44px'
},400);
}
}
});
$(document).ready(function() {
if ($(window).height() >= $(document).height() )
{
$('footer').data('size','hide');
}
else
{
$('footer').data('size','big');
}
});
谢谢大家
最佳答案
看看这是不是你想要的。对您的 JS 进行了很多更改,这对我来说是很多: http://jsfiddle.net/EDWHX/3/
JS:
$(function(){
$('footer').hide();
if($(document).height() < $(window).height()){
$('footer').show();
}
$(window).resize(function(){
console.log("resized");
if($(document).height() > $(window).height()){
console.log("hide footer now");
$('footer').slideUp('slow');
}
else{
$('footer').slideDown('slow');
}
});
});
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() >= $(document).height() - 0)
{
$('footer').slideDown('slow');
$('#white2').stop().animate({
bottom:'6px'
},400);
}
else
{
$('footer').slideUp('slow');
$('#white2').stop().animate({
bottom:'-44px'
},400);
}
});
$(document).ready(function() {
if ($(window).height() >= $(document).height() )
{
$('footer').data('size','hide');
}
else
{
$('footer').data('size','show');
}
});
CSS 更改:
footer {
position: fixed;
bottom:0px;
height: 40px;
width: 100%;
margin: 0 auto;
text-align: center;
border-top:2px solid #6ce6d5;
background: white;
z-index: 100;
}
关于jquery - 如果在页面底部或页面较短则显示页脚,否则隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18326708/
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我希望我的UserPrice模型的属性在它们为空或不验证数值时默认为0。这些属性是tax_rate、shipping_cost和price。classCreateUserPrices8,:scale=>2t.decimal:tax_rate,:precision=>8,:scale=>2t.decimal:shipping_cost,:precision=>8,:scale=>2endendend起初,我将所有3列的:default=>0放在表格中,但我不想要这样,因为它已经填充了字段,我想使用占位符。这是我的UserPrice模型:classUserPrice回答before_val
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
如果我使用ruby版本2.5.1和Rails版本2.3.18会怎样?我有基于rails2.3.18和ruby1.9.2p320构建的rails应用程序,我只想升级ruby的版本,而不是rails,这可能吗?我必须面对哪些挑战? 最佳答案 GitHub维护apublicfork它有针对旧Rails版本的分支,有各种变化,它们一直在运行。有一段时间,他们在较新的Ruby版本上运行较旧的Rails版本,而不是最初支持的版本,因此您可能会发现一些关于需要向后移植的有用提示。不过,他们现在已经有几年没有使用2.3了,所以充其量只能让更
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送