Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery - use function for action

0 votes
82 views
added Mar 13, 2019 in jQuery by LC Marshal Captain (25,840 points)
$(function () {

    var counter = 0,
        myElements = $('#element1, #element2');

    function showElement () {
        myElements.hide()  
            .filter(function (index) { return index == counter % 3; }) // figure out correct element to show
            .show('fast'); // and show it

        counter++;
    }; // function to loop through elements and show correct element

    showElement(); // show first element    

    setInterval(function () {
        showElement(); // show next element
    }, 10 * 1000); // do this every 10 seconds    

});

 

2 Responses

0 votes
responded Mar 13, 2019 by LC Marshal Captain (25,840 points)
function showSto () {
    $('.sto-ads').show();
    $('.sto-ads').addClass('in');
    $('.sto-ads .slide-close').on('click', function(){
      $(this).parent().parent().removeClass('in');
    });
  };

  if ($('body').hasClass('front')) {
    showSto(); 
    console.log('front')
  }
  else {
    showSto(); 
    console.log('not-front')
  }

 

0 votes
responded Jun 18 by lcjr Second Warrant Officer (3,200 points)
function closePopup() {
  if($('.gold-winner-popup').hasClass('active')) {
    $('.gold-winner-popup').click(function () {
      $(this).fadeOut(400).removeClass('active');
    });
  }
};


$('#pop1').click(function () {
  $('.gold-winner-popup.pop1 ').addClass('active').slideDown(300);
  // use here
  closePopup(); 
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...