2016-08-12 4 views
6

Я пытаюсь иметь два раздела на одной странице, раздел входа и приложение.Слайд два divs одновременно

Идея onLoginSubmit() заключается в том, чтобы сдвинуть влево раздел входа в систему и вставить вправо приложение.

Рассмотрим этот HTML:

<section id="login-section"> 

</section> 
<section id="app-section" style="display: none;"> 

</section> 

И в JS я использую:

$('#login-section').toggle("slide", { direction: "left" }, 500); 
$('#app-section').toggle("slide", { direction: "right" }, 500); 

Что происходит, что Логин-раздел не выскользнуть слева, но приложение-секция получает только после переход закончился, поэтому я получаю фон по умолчанию, когда раздел входа выходит из экрана.

Я использую jQuery и jQuery UI. Любая помощь приветствуется.

+0

Эта идея имеет настоящую проблему безопасности. Весь ваш личный контент будет виден даже без входа в систему. 'display: none' только делает это невидимым в визуализированном документе, но не в коде, поэтому все люди смогут видеть содержимое успешного входа в систему –

+0

. Я знаю об этом. Это всего лишь небольшой проект, который я делаю, чтобы изучить интерфейс. – HelderMPinhal

+0

Учиться в интерфейсе включает в себя безопасность и лучшие практики. Научиться делать это неправильно, это не учиться. –

ответ

1

var $div1 = $('#login-section'), 
 
    $div2 = $('#app-section'), 
 
    currentDiv = 'div1', 
 
    $button = $('button'); 
 

 
$div2.hide(); 
 
$button.text('Toggle ' + currentDiv); 
 

 
$(document).on('click', 'button', function (evt) { 
 
    $div1.toggle('slide', {direction: 'right'}, 'slow'); 
 
    $div2.toggle('slide', {direction: 'left'}, 'slow'); 
 
    
 
    currentDiv = (currentDiv === 'div1') ? 'div2' : 'div1'; 
 
    $button.text('Toggle ' + currentDiv); 
 
});
#login-section{ 
 
    width: 500px; 
 
    height: 100px; 
 
    background-color: green; 
 
    position: absolute; 
 
    top: 0px; 
 
    left: 0px; 
 
} 
 

 
#app-section{ 
 
    width: 500px; 
 
    height: 100px; 
 
    background-color: blue; 
 
    position: absolute; 
 
    top: 0px; 
 
    left: 0px; 
 
} 
 

 
.clear { 
 
    clear: both; 
 
} 
 

 
.container { 
 
    width: 800px; 
 
    position: relative; 
 
    left: 100px; 
 
    height: 100px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/ui/1.9.1/jquery-ui.min.js"></script> 
 
<p>some content here </p> 
 
<div class="container"> 
 
    <div id="login-section"></div> 
 
    <div id="app-section"></div> 
 
</div> 
 
<button>Toggle</button>

0

HTML

<section id="login-section" > 

</section> 
<section id="app-section" style="display: none;"> 

</section> 

JS

$(document).ready(function() { 

$('#login-section').toggle("slide", { direction: "left" }, 500); 
$('#app-section').toggle("slide", { direction: "right" }, 500); 

}) 

CSS

#login-section { 
     background: red; 
     //padding: 20px; 
     width: 100%; 
     height: 100%; 
     left : 0; 
     top : 0; 
     position : absolute; 
    } 

    #app-section { 
     background: blue; 
     //padding: 20px; 
     width: 100%; 
     height: 100%; 
     right:0; 
     top : 0; 
    } 

Пожалуйста, проверьте этот Fiddle

0

HTML

<section id="login-section"> 
hi 
</section> 
<section id="app-section"> 
there 
</section> 
<div id="toggle-sections"> 
click to toggle 
</div> 

CSS

#login-section { 
background-color: green; 
} 

#app-section { 
    background-color: blue; 
    display: none; 
} 

#login-section, #app-section { 
    position: absolute; 
    width: 100%; 
    top: 0px; 
} 

#toggle-sections { 
    position: relative; 
    top: 50px; 
} 

JQuery

$('#toggle-sections').click(function() { 
    $('#login-section').toggle("slide", { direction: "left" }, 500); 
    $('#app-section').toggle("slide", { direction: "right" }, 500); 
}); 

Демо скрипку https://jsfiddle.net/6cndzc6j/

Смежные вопросы