English 中文(简体)
我如何在使用j Query的两页内容之间增加影响?
原标题:How do I add fade effect between content on two pages using jQuery?

I have designed a simple website with a home and about page and a sliding contact form. You can see the site here.

我愿在指数和大约页之间增加一点。 我认为,最简单的解决办法是失败的,但贬低内容也可能看好。 我试图执行关于CSS tricks的活页文字,但可以推一下它与我已经建立的导航系统合作,其效果也不符合正确的秩序。 我认为,命令必须:

  1. Fade (or slide) out current page
  2. Alter height of page to fit new content
  3. Fade (or slide) in new page

我想知道,有人是否可以建议一种适当的方法,以实现我所期望的效果。

感谢

Nick

<><>ADDED

CLOSE BUTTON CLICK FUNCTION:

<script type="text/javascript">
$(document).ready(function(){
    $(".close").click(function(){
        $("#panel").slideUp("slow");
        $("#home").addClass("current");
        $("#contact").removeClass("current");
        return false;
    });
});
</script>

执行:

$("nav").delegate("a.fade", "click", function ()
    {
        window.location.hash = $(this).attr("href");
        $("#panel").slideUp("slow");
        $(this).addClass("current");
        $("#contact").removeClass("current");
        return false;
    });

FULL DYNAMICPAGE.JS

$(function ()
{

    var newHash = "",
        $mainContent = $("#main-content"),
        $pageWrap = $("#page-wrap"),
        baseHeight = 0,
        $el,
        $panel = $("#panel");

    $panel.visible = false;


    $(window).bind( hashchange , function ()
    {

        newHash = window.location.hash.substring(1);

        if (newHash)
        {
            if ($panel.visible)
            {
                $pageWrap.animate({ height: "-=" + $panel.height() + "px" }, function ()
                {
                    $pageWrap.height($pageWrap.height());
                    $panel.visible = false;
                });
                $panel.slideUp();
                baseHeight = $pageWrap.height() - $mainContent.height() - $panel.height();
            }
            else
            {
                $pageWrap.height($pageWrap.height());
                baseHeight = $pageWrap.height() - $mainContent.height();
            }

            $mainContent
                .find("#guts")
                .fadeOut(500, function ()
                {
                    $mainContent.hide().load(newHash + " #guts", function ()
                    {
                        $pageWrap.animate({ height: baseHeight + $mainContent.height() + "px" }, function ()
                        {
                            $mainContent.fadeIn(500);
                            $pageWrap.css("height", "auto");
                        });

                });
                });
        };
    });

    $("nav").delegate("a.fade", "click", function ()
    {
        window.location.hash = $(this).attr("href");
        $("#panel").slideUp("slow");
        $(this).addClass( clicked );
        $("a").not(this).removeClass( clicked );
        $(".current", this).stop().animate({
            opacity: 1
        }, {
            duration: 100,
            specialEasing: {
                opacity:  linear ,
            },

        });

        $(".current").not($(".current",this)).stop().animate({
                    opacity: 0
                }, {
                    duration: 2000,
                    specialEasing: {
                        opacity:  linear ,
                    },

                });

        return false;
    });

    $("#nav-bottom").delegate("a", "click", function ()
    {
        $("#panel").slideDown("slow");
        return false;
    });


    $("#contact").click(function ()
    {
        $("#panel").slideDown("slow");
//        $(this).addClass("current");
//        $("#home, #about").removeClass("current");
        $(this).addClass( clicked );
        $("a").not(this).removeClass( clicked );
        $(".current", this).stop().animate({
            opacity: 1
        }, {
            duration: 100,
            specialEasing: {
                opacity:  linear ,
            },

        });

        $(".current").not($(".current",this)).stop().animate({
                    opacity: 0
                }, {
                    duration: 2000,
                    specialEasing: {
                        opacity:  linear ,
                    },

                });

        $panel.visible = true;
        return false;
    });

    $(".close").click(function ()
    {
        $("#panel").slideUp("slow");
        $panel.visible = false;


        $(".current","#nav3").stop().animate({
            opacity: 0
        }, {
            duration: 2000,
            specialEasing: {
                opacity:  linear ,
            },

        });   

        return false;
    });

    $("nav a").hover(
        function() {
            if(!$(this).hasClass( clicked )){

            $(".current", this).stop().animate({
                opacity: 1
            }, {
                duration: 300,
                specialEasing: {
                    opacity:  linear ,
                },

            });
            }
        }, function() {
        if(!$(this).hasClass( clicked )){
            $(".current", this).stop().animate({
                opacity: 0
            }, {
                duration: 2000,
                specialEasing: {
                    opacity:  linear ,
                },

        });

        }
    });

    $(window).trigger( hashchange );

});

<><><><>>><>>>>><>>>>>>

 <div class="nav-image"><img src="images/bodhi-leaf-brown.png"></div>

 <div class="current"><img src="images/bodhi-leaf-green.png"></div>
 <div class="text"><img src="images/home.png"></div>

 </a> </div>

 <div class="nav-image"><img src="images/bodhi-leaf-brown.png" class="flip"></div>

 <div class="current"><img src="images/bodhi-leaf-green.png" class="flip"></div>
 <div class="text"><img src="images/about.png"></div>

 </a> </div>

 <a href="index.html" class="" id="contact">

 <div class="nav-image"><img src="images/bodhi-leaf-brown.png"></div>

 <div class="current"><img src="images/bodhi-leaf-green.png"></div>
 <div class="text"><img src="images/contact.png"></div>

 </a> </div>

<>CSS

nav {
    width: 650px;
    height: 170px;
    position: absolute;
    top: 100;
    left: 200;
}

#nav1 {
    position: absolute;
    top: 0;
    left: 120px;
}

#nav2 {
    position: absolute;
    top: 0;
    left: 340px;
}

#nav3 {
    position: absolute;
    top: 0;
    left: 560px;
}


.nav-image  {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 1;

}

.current {
    position: absolute;
    top: 0px;
    left: 0px;
    z-index: 2;
    opacity: 0;
}
最佳回答

如果你想要遵守安全局的三方守则,我就认为有可能使安理会为你们工作。

Animation order

在我第一次尝试时,我已经注意到了,但——你回过来——失败、新内容的落差,然后调整了高温的降温令是sil的。 你们可以通过推翻 an令来做到这一点。

$pageWrap.animate({ height: baseHeight + $mainContent.height() + "px" }, function () { $mainContent.fadeIn(200); });

<><>中>

您可以将接触表排除在启动更改之外,具体做法是,在代表中列入哪些内容(例如链接<代码>#contact)。

$("nav").delegate("a:not(#contact)", "click", function () { ... }

这可能或可能不会做你想要的东西,例如,你可能实际上想要接触形式来添加一根 has,以便人们能够与它联系。 在此情况下,您可在散射活动中添加if>,以核对#contact(或不管怎样)。

<><>Edit>/strong>

在下文的评论意见之后,这一动态页码编码为pageWrap。 height升后(即接触物工作)的高度为汽车,在接触表可见时,也重新计算高点,以便改变页面。

Edit 2

在接触表明显和有条不紊的环节时,顺利处理滚动问题。 接触表没有顺利发展,因为你将原封(扩展)高度储存在<条码>hashChange,并作了相应调整。 一旦 an酸finished结束,固定高点通过特别安全局被拆除,它就会跃升至比目前高得多的水平。 我补充说,如果接触表需要隐蔽,则会调整高度。

这些链接之所以有缺陷,是因为在<代码>#guts div(以及实际上在#main-content部分内,这些部分实际编码。 如果你不这样做,事情就会更好。 不幸的是,他们开始在删除旧的<代码>#guts内容与添加新内容之间的差距方面跳跃,因此,你可以使用下文所述的缩略语,以接手。

但我并不认为这是一个伟大的解决办法。 如果是你,我就把内容、缩略语<代码>#guts隐藏在新的高度,然后添加内容,如<代码>#guts。 社会保障局从未失去固定的高度。 采用<代码>animate,也使你能够提出分析意见,如果你太快地点击事情,这有时会成为一个问题。

$(function ()
{

    var newHash = "",
        $mainContent = $("#main-content"),
        $pageWrap = $("#page-wrap"),
        baseHeight = 0,
        $el,
        $panel = $("#panel");

    $panel.visible = false;

    $("nav").delegate("a", "click", function ()
    {
        window.location.hash = $(this).attr("href");
        return false;
    });

    $(window).bind( hashchange , function ()
    {

        newHash = window.location.hash.substring(1);

        if (newHash)
        {
            if ($panel.visible)
            {
                $pageWrap.animate({ height: "-=" + $panel.height() + "px" }, function ()
                {
                    $pageWrap.height($pageWrap.height());
                    $panel.visible = false;
                });
                $panel.slideUp();
                baseHeight = $pageWrap.height() - $mainContent.height() - $panel.height();
            }
            else
            {
                $pageWrap.height($pageWrap.height());
                baseHeight = $pageWrap.height() - $mainContent.height();
            }

            $mainContent
                .find("#guts")
                .fadeOut(500, function ()
                {
                    $mainContent.hide().load(newHash + " #guts", function ()
                    {
                        $pageWrap.animate({ height: baseHeight + $mainContent.height() + "px" }, function ()
                        {
                            $mainContent.fadeIn(500);
                            $pageWrap.css("height", "auto");
                        });

                        $("nav a").removeClass("current");
                        $("nav a[href="" + newHash + ""]").addClass("current");
                    });
                });
        };
    });

    $("#contact").click(function ()
    {
        $("#panel").slideDown("slow");
        $(this).addClass("current");
        $("#home, #about").removeClass("current");
        $panel.visible = true;
        return false;
    });

    $(".close").click(function ()
    {
        $("#panel").slideUp("slow");
        $(curTab).addClass("current");
        $("#contact").removeClass("current");
        $panel.visible = false;
        return false;
    });

    $(window).trigger( hashchange );

});

CSS

#nav-bottom {
    margin: -15px 0 15px -100px;
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 200px;
}
问题回答

Javascript is not really intended to transition between pages but I guess you could hack something together whereby when someone clicks on the link you go $( body ).fadeout(slow); the only problem then is that the page could well load before the effect has time to complete, of course you can cancel default behavior, do the effect and then go to the desired page..

检查这一来源,在港口,但乌可以尝试:

rel=“nofollow”>jquery-transitions-como-fazer-transicoes-de-paginas

<><><><>>>>>

<div id="container">
<h1>This is the index </h1>
Some text with <a class="transition" href="http://jsfiddle.net/ruanltbg/Ns97H/3/embedded/result/">link</a>.This link will do the effect

<div id="container">
<h1>Other page </h1>
Will appear with a <a class="transition" href="http://jsfiddle.net/ruanltbg/WvD7Q/1/embedded/result/">link</a> to the index.

<>strong>js:

$("#container").fadeIn(2000);
$("a.transition").click(function(event){
    event.preventDefault();
    link = this.href;
    $("body").fadeOut(1000, function(){
        window.location = link;
    });
});

Demo





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签