MediaWiki:Gadget-RainbowHeaders.js: Difference between revisions

From Elwiki
mNo edit summary
mNo edit summary
Line 11: Line 11:
         startH = Math.max(0, startH);
         startH = Math.max(0, startH);
         endH = Math.min(359, endH);
         endH = Math.min(359, endH);
        console.log(startH, endH);
         th.css('background-image', 'linear-gradient(to right, hsl(' + startH + ', 50%, 50%), hsl(' + endH + ', 50%, 50%))');
         th.css('background-image', 'linear-gradient(to right, hsl(' + startH + ', 50%, 50%), hsl(' + endH + ', 50%, 50%))');
     });
     });
});
});

Revision as of 08:13, 3 June 2016

$('tr.rainbow').each(function(e){
    var tr = $(this);
    if(!(tr.css('position') in ['relative', 'absolute'])){
        tr.css('position', 'relative');
    }
    var trWidth = tr.width();
    $(this).children('th').each(function(e){
        var th = $(this);
        var startH = Math.floor(th.offset().left / trWidth * 360);
        var endH = Math.floor((th.offset().left + th.width()) / trWidth * 360);
        startH = Math.max(0, startH);
        endH = Math.min(359, endH);
        console.log(startH, endH);
        th.css('background-image', 'linear-gradient(to right, hsl(' + startH + ', 50%, 50%), hsl(' + endH + ', 50%, 50%))');
    });
});