创建左/右过渡效果

发布于 2024-11-14 06:19:47 字数 963 浏览 8 评论 0原文

我正在尝试创建像视频 http://www.youtube 中发布的幻灯片过渡效果.com/watch?v=SZTiJmclaRc

单击按钮时,当前 div#1 将从左侧滑出并隐藏自身,而另一个 div#2 将从右侧滑动并移动到前一个滑出 div 的位置。

当按钮再次触发时,div#2 将向右滑出,而之前隐藏的 div#1 将从左侧滑出。

我一直在尝试修改 http://jsfiddle.net/qSvDz/ 处的代码,如下所示,但我可以似乎没有得到我想要的结果。

有人可以分享一些关于如何做到这一点的想法吗?

function toggleDivs() {
var $home = $("#home");
var $memberHome = $("#member-home");
var $slideOut, $slideIn;

// See which <divs> should be animated in/out.
if ($home.position().left < 0) {
    $slideIn = $home;
    $slideOut = $memberHome;
}
else {
    $slideIn = $memberHome;
    $slideOut = $home;
}

$slideOut.animate({
    left: "-" + $slideOut.width() + "px"
}, function() {
    $slideIn.animate({ left: "0px" });
});
}

$("button").bind("click", function() { 
    toggleDivs();
});

谢谢 火

I am trying to create a slide transition effect like the one posted in the video http://www.youtube.com/watch?v=SZTiJmclaRc.

When the button is clicked the current div#1 will be sliding out to the left and hide itself while another div#2 will be sliding from the right and move to the location of of the previous slided out div.

And when the button is trigger again the div#2 will be sliding out to right while the previously hide div#1 will be sliding out from left.

I have been trying to modify the code at http://jsfiddle.net/qSvDz/ as below but I can't seem to get the result I wanted.

Could anyone pls share me some thought on how to do it.

function toggleDivs() {
var $home = $("#home");
var $memberHome = $("#member-home");
var $slideOut, $slideIn;

// See which <divs> should be animated in/out.
if ($home.position().left < 0) {
    $slideIn = $home;
    $slideOut = $memberHome;
}
else {
    $slideIn = $memberHome;
    $slideOut = $home;
}

$slideOut.animate({
    left: "-" + $slideOut.width() + "px"
}, function() {
    $slideIn.animate({ left: "0px" });
});
}

$("button").bind("click", function() { 
    toggleDivs();
});

Thanks
Fire

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-11-21 06:19:47

像这样的东西吗?

http://jsfiddle.net/k_rma/VmSX4/

HTML:

<div id="container">
    <div id="inner">
        <div id="home">
            <button>Click</button>
        </div>
        <div id="member-home">
            <button>Click</button>
        </div>
    </div> 
</div>

JS/JQUERY:

function toggleDivs() {
    var $inner = $("#inner");

    // See which <divs> should be animated in/out.
    if ($inner.position().left == 0) {
        $inner.animate({
            left: "-400px"
        });
    }
    else {
        $inner.animate({
            left: "0px"
        });
    }
}

$("button").bind("click", function() {
    toggleDivs();
});

CSS:

#container {
    position:relative;
    border: 1px solid black;
    width:400px;
    height:600px;
    overflow:hidden
}
#inner {
    position: relative;
    width: 800px; 
}
#home {
    position:absolute;
    width: 400px;
    height: 600px;
    background-color: red;
}

#member-home {
    position:absolute;
    left:400px;
    width: 400px;
    height: 600px;
    background-color: green;
}

Something like this?

http://jsfiddle.net/k_rma/VmSX4/

HTML:

<div id="container">
    <div id="inner">
        <div id="home">
            <button>Click</button>
        </div>
        <div id="member-home">
            <button>Click</button>
        </div>
    </div> 
</div>

JS/JQUERY:

function toggleDivs() {
    var $inner = $("#inner");

    // See which <divs> should be animated in/out.
    if ($inner.position().left == 0) {
        $inner.animate({
            left: "-400px"
        });
    }
    else {
        $inner.animate({
            left: "0px"
        });
    }
}

$("button").bind("click", function() {
    toggleDivs();
});

CSS:

#container {
    position:relative;
    border: 1px solid black;
    width:400px;
    height:600px;
    overflow:hidden
}
#inner {
    position: relative;
    width: 800px; 
}
#home {
    position:absolute;
    width: 400px;
    height: 600px;
    background-color: red;
}

#member-home {
    position:absolute;
    left:400px;
    width: 400px;
    height: 600px;
    background-color: green;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文