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
11 views
added Mar 13 in jQuery by LC Marshal Captain (20,510 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    

});

 

1 Response

0 votes
responded Mar 13 by LC Marshal Captain (20,510 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')
  }

 

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