我的网站有问题,我想做切换完全像这个例子:
http://www.templatemonster.com/demo/36298.html我有顶部栏(宽度50px)包括箭头切换和在页面的其余部分,我有iframe的网站。
所有我想做的就是切换动画效果-将顶部栏从绝对顶部0移动到绝对顶部50以隐藏,同时我想将iframe高度从100%-50px更改为100%。
我做了这个脚本,它可以完美地隐藏顶部栏,但不会再次将其显示为默认值。
你能帮帮我吗?谢谢
发布于 2014-02-08 21:42:20
你有没有用click代替live?live适用于您定义事件侦听器时不存在的元素,我猜您的.show-bar元素一开始就不存在。试试这个:
$('#demo').height($(window).height()-50); // default iframe height
$(".hide-bar").live('click',function(){ // hide top bar
$("#header-bar").animate({"top":"-50px"},300);
$("#demo").animate({"height":$(window).height()-0},300);
$(this).removeClass();
$(this).addClass("show-bar");
});
$(".show-bar").live('click',function(){ // show top bar
$("#header-bar").animate({"top":"0px"},300);
$("#demo").animate({"height":$(window).height()-50},300);
$(this).removeClass();
$(this).addClass("hide-bar");
}); 注意:这将适用于jQueryv1.7(在1.9方法中删除了live )
以下是较新版本的jquery的相同代码:
$('#demo').height($(window).height()-50);
$(document).on('click',".hide-bar",function(){
$("#header-bar").animate({"top":"-50px"},300);
$("#demo").animate({"height":$(window).height()},300);
$(this).removeClass();
$(this).addClass("show-bar");
});
$(document).on('click',".show-bar", function(){
$("#header-bar").animate({"top":"0px"},300);
$("#demo").animate({"height":$(window).height()-50},300);
$(this).removeClass();
$(this).addClass("hide-bar");
});发布于 2014-02-08 21:55:53
我希望下面的解决方案能帮助你。
css代码:
#header-bar {position:fixed; top:0; left:0; width:200px; background-color:grey; height:50px;}
#close-bar { position:absolute; bottom:-20px; background:red; color:white;}超文本标记语言代码:
<section id="header-bar" class="txt-highlight-color bg-color bg-pattern">
<span id="close-bar" class="hide-bar">close button</span>
</section>jQuery代码:
var speed = 300;
$('#close-bar').on('click', function(){
var $$ = $(this);
if( $$.is('.hide-bar') ){
$('#header-bar').animate({top:-50}, speed);
$$.removeClass('hide-bar')
} else {
$('#header-bar').animate({top:0}, speed);
$$.addClass('hide-bar')
}
});发布于 2014-02-09 23:51:13
好了,伙计们,我已经知道了,这是我的最终代码:
$(function() {
$('#demo').height($(window).height()-$("#header-bar").height());
var speed = 300;
$(document).on('click',".hide-bar",function(){
$("#header-bar").animate({"top": - $("#header-bar").height()},speed);
$("#demo").animate({"height":$(window).height()},speed);
$(this).removeClass();
$(this).addClass("show-bar");
});
$(document).on('click',".show-bar", function(){
$("#header-bar").animate({"top":"0px"},speed);
$("#demo").animate({"height":$(window).height()-$("#header-bar").height()},speed);
$(this).removeClass();
$(this).addClass("hide-bar");
});
});有了这个,我只能在CSSfile中设置#header-bar宽度,它会改变所有的宽度
谢谢你的帮忙
https://stackoverflow.com/questions/21646587
复制相似问题