两栏网站调整大小

时间:2013-04-09 15:36:17

标签: javascript jquery html5 css3

如何创建一个两列,其中一个div在翻转时占据整个屏幕?

1 个答案:

答案 0 :(得分:1)

这里有一个非常简单的示例,说明如何在jquery中完成此操作,只是为了给你一些方向:
jsfiddle

<强> HTML

<div id="wrapper">
    <div class="col one"></div>
    <div class="col two"></div>
</div>

<强> JS

$(function() {
    // Mouse over div
    $(".col").mouseenter(function() {
        // If it's the second div, we want to move it left while making it bigger
        if($(this).hasClass("two")) {
            // we use .stop to stop all current animations
            // Also we add an active class to put it on top
            $(this).stop().addClass("active").animate({"left": "0px", "width": "98%"}, 500);
        }
        // otherwise we dont care, just make it bigger
        else {
             // Also we add an active class to put it on top
            $(this).stop().addClass("active").animate({"width":"98%"}, 500);
        }
    });
    // Mouse off div
    $(".col").mouseleave(function() {
        // If it's the second div, we want to move it back to 45% while making it smaller
        if($(this).hasClass("two")) {
            $(this).stop().animate({"left": "50%", "width":"45%"}, 500).removeClass("active");
        }
        else {
             $(this).stop().animate({"width":"45%"}, 500).removeClass("active");
        }
    });
});
相关问题