必须有更好的方法来做到这一点。
- 将悬停事件添加到 #footer 以复制(通过 clone() )页脚菜单并显示它,除非页脚显示在 $(window) 中
笔记
div#footer 的 div#menu 子项的位置:固定在屏幕底部。
使用标签页脚到内容 css hack 的底部
我怎样才能更好地优化代码......尤其是在显示实际页脚时我不希望它弹出的部分?
CSS:
.floatingMenu { display:block; position:fixed; width:100%; }
#menu{position:fixed;bottom:0;width:100%;z-index:10;}
/**footer at bottom**/
html, body, #wrap, #body-container { height: 100%; }
body > #wrap {height: auto; min-height: 100%;}
body > #body-container {height:auto;min-height:100%}
#main{padding-bottom:300px;min-height:250px;}
#footer{position:relative;margin-top:-300px;height:300px;clear:both;}
.clearfix:after {content: ".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix {display: inline-block}
html .clearfix { height: 1%}
.clearfix {display: block}
HTML
<body>
<div id="body-container">
<div id="main" class="clearfix">
</div>
</div>
<div id="footer">
<div id="menu">
<div id="menu-footer" class="menu-container">
<div class="wrap">
<?php get_template_part( 'menu', 'primary' ); // Loads the menu-primary.php file ?>
</div>
</div>
</div> <!-- #menu -->
<div id="footer-links" class="footer-color">
<?php wp_footer(); // WordPress footer hook ?>
<?php echo apply_atomic_shortcode( 'footer_content', hybrid_get_setting( 'footer_insert' ) ); ?>
</div>
</div><!-- #footer-links -->
</div><!-- #footer -->
</body>
JS V1(下面还有更多版本)
<script type="text/javascript">
function addHoverEvent(varObject, varSpeed) {
varObject.css("display", "block").addClass('floatingMenu')
.animate({'bottom': '18px'}, varSpeed / 0.75);
}
function exitMenu(varObject, varSpeed) {
varObject.stop(true,true).delay(1050).animate({'bottom': '-100%'}, varSpeed,
function(){
$(this).removeClass('floatingMenu');
varObject.css("display", "none");
}
);
}
$(document).ready(function() {
var
varSpeed = 900,
varBindObject = $('#footer');
varObject = $('#footer-links').clone().appendTo('#footer');
varObject.css("display", "none");
$(window).scroll(function() {
var
varBindObject = $('#footer'),
y = $(window).scrollTop(),
w = $(window).height(),
c = $('#footer-links').offset();
if(y+w>c.top) {
//varBindObject.data("events");
varBindObject.die();
} else {
varBindObject
.live('mouseenter', function() {
addHoverEvent(varObject, varSpeed);})
.live('mouseleave', function () {
exitMenu(varObject, varSpeed);});
}
});
varBindObject
.live('mouseenter', function() {
addHoverEvent(varObject, varSpeed);
})
.live('mouseleave', function () {
exitMenu(varObject, varSpeed);
});
});
</script>
JS V2
<script type="text/javascript">
function addHoverEvent(varObject, varSpeed) {
varObject.css("display", "block").addClass('floatingMenu')
.animate({'bottom': '18px'}, varSpeed / 0.75
// { duration: 'fast',
// easing: 'in-out'
// }
);
}
function exitMenu(varObject, varSpeed) {
varObject.stop(true,true).delay(900).animate({'bottom': '-100%'}, varSpeed,
function(){
$(this).removeClass('floatingMenu');
varObject.css("display", "none");
}
);
}
function isOnScreen(element) {
var offset = element.offset().top - $(window).scrollTop();
if(offset > window.innerHeight){
// Not in view so scroll to it
return false;
}
return true;
}
$(document).ready(function() {
var
varSpeed = 900,
varBindObject = $('#footer');
varObject = $('#footer-links').clone().appendTo('#footer');
varObject.css("display", "none");
if(isOnScreen($('#footer-links'))) {
}else{
varBindObject
.live('mouseenter', function() {
addHoverEvent(varObject, varSpeed);
})
.live('mouseleave', function () {
exitMenu(varObject, varSpeed);
});
}
$(window).scroll(function() {
var
varBindObject = $('#footer'),
y = $(window).scrollTop(),
w = $(window).height(),
c = $('#footer-links').offset();
varBindObject
.live('mouseenter',
function() {
addHoverEvent(varObject, varSpeed);
})
.live('mouseleave',
function () {
exitMenu(varObject, varSpeed);
});
if(isOnScreen($('#footer-links'))) {
//if(y+w>c.top) {
varBindObject.die();
}
});
});
</script>