R
R
realnin2015-11-11 03:04:13
JavaScript
realnin, 2015-11-11 03:04:13

Two oneclick functions?

There are such two functions.
How to make these functions in one button, so that when pressed, 1 function is performed, when pressed again, 2 functions, then again 1, and so on in a circle?

function OpenNewMenu() {

    $("#new_darkness").fadeIn(300);
    $("#new_menu_right").animate( { left:"0px"}, {queue:false, duration:160 }) // mmessage_block
                        .animate( { left:"0px"}, 300);
    $("#menu_open_button").animate( { opacity:"0.4"}, {queue:false, duration:160 }) // mmessage_block
                          .animate( { opacity:"0.4"}, 300);
    //$("body").attr("style");
    //$("body").attr("style", "overflow-y: hidden;");
}

function HideNewMenu() {

    //$("body").attr("style");
    //$("body").attr("style", "overflow-y: auto;");
    $("#new_darkness").fadeOut(300);
    $("#new_menu_right").animate( { left:"-320px"}, {queue:false, duration:160 }) // mmessage_block
                        .animate( { left:"-320px"}, 300);   
    $("#menu_open_button").animate( { opacity:"1"}, {queue:false, duration:160 }) // mmessage_block
                          .animate( { opacity:"1"}, 300);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-11-11
@realnin

For example like this

$('#menu_open_button').on('click', function(){
  var menu = $('#new_menu_right').toggleClass('hidden')
  if (menu.hasClass('hidden')) {
    OpenNewmenu()
  } else {
    Hidenewmenu()
  }
})

You can store the state not in the class but in the data attribute. Or focus on the current transparency values ​​or whatever you have. But it seems to me more convenient with a class - thus, part of the appearance changes can also be done in css. And sometimes all this can be done through css, and then only toggleClass will remain in js!
Example: jsfiddle.net/kdoxe06o

A
Alexander Zachinalov, 2015-11-11
@SanDiesel

$('.mySelector').toggle(function() {
  OpenNewMenu()
}, function() {
  Hidenewmenu()
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question