切换左右滑动元素组 Javascript

Toggle Slide right and left element group Javascript

我尝试为搜索、语言和联系人选项创建一个 header 导航。 (下面的演示)

所有元素都是可点击的。我无法管理内容滑入、移动其他图标并在单击任何其他元素时滑回。

PS:搜索栏已经在我的 jquery、jquery ui 文档中工作,可以向内和向后滑动(在 JSFiddle 上不起作用不知道为什么..,但 p 标签不会滑入。搜索栏正在使用这样的代码:

$(function () {
      $(".lupeIcon").click(function (){
            $(".searchField").addClass("searchFieldWidthExtender",2000)
            $(".telefonField").hide("slide", {direction: "right"}, 2000);
            $(".globusField").hide("slide", {direction: "right"}, 2000);

  });
        });     

)

这是代码

HTML:

    <body>
 <nav>
<div class="navIcon telefonIcon"><p class="telefonField">12 346 5</p><i class="fa fa-phone" aria-hidden="true"></i></div>
<div class="navIcon lupeIcon"><input class="searchField" type="text" name="search"><i class="fa fa-search" aria-hidden="true"></i></div>
<div class="navIcon globusIcon"><p class="globusField">DE | EN</p><i class="fa fa-globe" aria-hidden="true"></i></div>
                </nav>

                </body>

CSS:

div.navIcon{
    float: left;
    margin: 0 40px 0 0;
    line-height: 95px;
    padding: 0;
    font-size: 20px;
    color: red;
        -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -ms-transition: all 1s;
    -o-transition: all 1s;
    transition: all 1s;
    display: -webkit-box; 
}
.searchField {
    display: none;
    height: 30px;
    margin: 0 10px 0 0;
    border: none;
    border-radius: 30px;
    box-shadow: inset 0 0 2px red;

}

.telefonField, .globusField { 
    display: none;
    height: 30px;
    margin: 0 10px 0 30px;
    vertical-align: middle;

}

Javascript:

     $(".telefonIcon").click(function (){
            $(".telefonField").addClass("displayInliner",2000)
            $(".telefonField").show("slide", {direction: "right"}, 2250);
            $(".searchField").hide();
            $(".globusField").hide("slide", {direction: "right"}, 2000);
  });

      $(".lupeIcon").click(function (){
            $(".searchField").addClass("searchFieldWidthExtender",2000)
            $(".searchField").show("slide", {direction: "right"}, 2250);
            $(".telefonField").hide("slide", {direction: "right"}, 2000);
<!--        $(".globusField").hide("slide", {direction: "right"}, 2000); -->            
                        $(".globusField").hide();

  });
      $(".globusIcon").click(function (){
            $(".globusField").addClass("displayInliner",2000)
            $(".globusField").show("slide", {direction: "right"}, 2250);
            $(".telefonField").hide("slide", {direction: "right"}, 2000);
            $(".searchField").hide("slide", {direction: "right"}, 2000);

  });

Demo with Icons

我制作了您的联系人菜单动画。
我玩得很开心。
我这样做是因为我觉得你想要的效果很好...

你会注意到我对你的代码做了很多改动。
我真的不知道如何一一解释所有的变化,所以尽管问。

看看我的CodePen


HTML

<body>
    <nav>
        <div class="field telefonField">12 346 5</div>
        <div class="navIcon telefonIcon">
            <i class="fa fa-phone" aria-hidden="true"></i>
        </div>


        <div class="field searchField">
            <input type="text" name="search">
        </div>
        <div class="navIcon lupeIcon">
            <i class="fa fa-search" aria-hidden="true"></i>
        </div>


        <div class="field globusField">DE | EN</div>
        <div class="navIcon globusIcon">
            <i class="fa fa-globe" aria-hidden="true"></i>
        </div>
    </nav>
</body>



CSS

div.navIcon {
    float: left;
    line-height: 95px;
    padding: 0;
    font-size: 20px;
    color: red;
}
.fa{
    float: left;
    line-height: 95px;
    color: red;
    padding: 0 6px;
}

.telefonField,
.searchField,
.globusField {
    float:left;
    display:none;
    width: 0;
    margin: 0;
    color: red;
    white-space:nowrap;
    overflow:hidden;
    line-height: 95px;
}

.searchField input{
    border: none;
    width:0px;
    border-radius: 30px;
    box-shadow: inset 0 0 2px red;
    outline: none;
    padding: 0.3em 0.5em 0.1em 0.7em;
}



jQuery

var showDelay = 2000;
var hideDelay = 2000;       // If you want to set a different hide delay
var thisWidth = 0;          // Element width are different
var searchField = false;    // For the input exception

$(".navIcon").click(function(){

    // Execute script only if «this» is not already displayed
    if( $(this).prev(".field").css("width") == "0px" ){

        if( $(this).prev(".field").hasClass("telefonField") ){
            thisWidth = "63px";
            searchField = false;
        }
        if( $(this).prev(".field").hasClass("searchField") ){
            thisWidth = "248px";
            searchField = true;
        }
        if( $(this).prev(".field").hasClass("globusField") ){
            thisWidth = "59px";
            searchField = false;
        }

        // Show it!
        $(this).prev(".field").animate({width:thisWidth},showDelay).show();

        // Hide the others
        $(".field").not( $(this).prev(".field") ).animate({width:"0px"},hideDelay,function(){
            $(this).hide();
        });

        // Also animated the input width...
        if(searchField){
            $(".searchField input").show().animate({width:"225px"},showDelay);
        }
    }
});