簡體   English   中英

使用jquery或css選擇器更改webkit css

[英]change webkit css with jquery or css selector

我可以使用jquery來控制自定義webkit滾動條的外觀嗎? 我很好奇,因為當我將鼠標懸停在::-webkit-scrollbar-thumb時,我想改變::-webkit-scrollbar-track-piece的背景顏色。 也許有一種方法可以用CSS做到這一點。 我願意接受任何解決方案! 謝謝!

我不認為有一種jQuery方法可以做到這一點,但在本機JavaScript中,您可以直接操作樣式表對象上的規則:

document.styleSheets[2].addRule("::-webkit-scrollbar", "width: 300px;");

這很好。 您還可以刪除規則並更改規則: http//www.javascriptkit.com/domref/stylesheet.shtml

你可以給你的<style>塊一個title ,這樣可以很容易地在styleSheets數組中找到它。 就像是:

for(var i = 0; i < document.styleSheets.length; i++) {
    var sheet = document.styleSheets[i];
    if(sheet.title == 'scrollbar') {
        for(var j = 0; j < sheet.rules.length; j++) {
            var rule = sheet.rules[j];
            if(rule.cssText.match("webkit-scrollbar")) {
                rule.style.backgroundColor="yellow";
            }
        }
    }
} ​

http://jsfiddle.net/nottrobin/hSEzY/1/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM