Question

I'm using a script for a touch swipe left hand sliding nav. How do I go about getting the nav to have the open toggle position when the page loads (instead of it being closed).

<script>
$(window).load(function(){
$("[data-toggle]").click(function() {
var toggle_el = $(this).data("toggle");
$(toggle_el).toggleClass("open-sidebar");
});

$(".swipe-area").swipe({
swipeStatus:function(event, phase, direction, distance, duration, fingers)
{
if (phase=="move" && direction =="right") {
$(".container").addClass("open-sidebar");
return false;
}
if (phase=="move" && direction =="left") {
$(".container").removeClass("open-sidebar");
return false;
}
}
}); 
});
</script>
Was it helpful?

Solution

In your html :

<div class="container open-sidebar"> 
  [content]
</div>

or in your Js :

$(window).load(function(){
  $(".container").addClass("open-sidebar"); // add class ".open-sidebar" to ".container" once dom is loaded
  $("[data-toggle]").click(function() {
  ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top