jQuery: Toggling between 3 classes (initially)

后端 未结 8 543
你的背包
你的背包 2020-11-29 09:32

I\'ve seen several posts here on SO but they are too specific in functionality and structure, and what I\'m looking for is something more universal that I or anyone can use

8条回答
  •  时光取名叫无心
    2020-11-29 10:23

    Cycles through the index of classes and toggles from one to ther other.

    var classes = ['border-top','border-right','border-bottom','border-left'];
    var border = 'border-top';
    var index = 0;
    var timer = setInterval( function() {
        var callback = function(response) {
            index = ( ++index == 4 ? 0 : index );
            $(element).html("text").toggleClass( border + " " + classes[index] );
            border = classes[index];
            };
        }, 1000 );
    

提交回复
热议问题