document.styleSheets

 

 

var RuleStr = "@keyframes ReRWFunc{0%{display:block !important;font-size:24px;width:245.4px;height:70px;line-height:70px;top:" + TopPX + "px;right:" + RightPX + "px;}99%{display:block !important;font-size:0px;width:10px;height:10px;line-height:10px;top:" + TargetTopPX + "px;right:" + TargetRightPX + "px;}100%{display:none !important;font-size:0px;width:0px;line-height:0px;top:0px;right:0px;}}";
            this.UpdateRuleFunc("ReRWFunc", this.TData.RuleIndex, RuleStr);
            $(".ReReadWordAction").html(TWord).css("animation", "ReRWFunc 1.5s forwards");
            this.TData.RuleIndex = 1;
            window.setTimeout(function () {
                $(".ReReadWordAction").html("").css("animation", "none");
            }, 2000);

 

 

// 更新规则
        UpdateRuleFunc: function (ruleName, FRFlag,NRuleStr) {
            if (FRFlag == 0) {
                var docStyle = document.createElement("style");
                docStyle.type = "text/css";
                docStyle.innerHTML = "@keyframes " + ruleName + "{0%{}100%{}}";  // 这里可以直接写成对应的第一次设置规则
                docStyle.rel = "stylesheet";
                $("head").append(docStyle);
            }
            var DSSArr = document.styleSheets;
            // 确定规则位置(暂定)
            //var RulesIndex = DSSArr.length - 1;
            var RulesIndex = 0;
            for (var i = 0; i < DSSArr.length; i++) {
                if (DSSArr[i].href == null) {
                    RulesIndex = i;
                    break;
                }
            }
            // 判断规则是否存在
            for (var i = 0; i < document.styleSheets[RulesIndex].rules.length; i++) {
                if (document.styleSheets[RulesIndex].rules[i].name = ruleName) {
                    document.styleSheets[RulesIndex].deleteRule(i);  // 删除0位置规则
                }
            }
            document.styleSheets[RulesIndex].insertRule(NRuleStr, 0);  // 添加不存在的规则,放在0位置
        },

 

上一篇:用原生JS读写CSS样式的方法总结(1)


下一篇:屏幕坐标转换成threejs的坐标