问答详情
源自:4-2 js配合动画属性实现图片无限滚动效果

Uncaught DOMException: Failed to execute 'insertRule' on 'CSSStyleSheet': Cannot access StyleSheet to insertRule

$(()=>{

var outerWidth = 600,

outerHeight = 400,

speed = 3;

var $marquee = $('.marquee');

var $content = $marquee.find('.content');

var $list = $content.find('.list');

var listLength = $list.length;

var contentWidth = outerWidth * listLength;

var style = document.styleSheets[0]

// console.log('style',style);

$marquee.css({

"width":`${outerWidth}px`,

"height":`${outerHeight}px`,

});

$list.css({

"width":`${outerWidth}px`,

"height":`${outerHeight}px`,

});

$content.css({

"width":`${contentWidth}px`,

"height":`${outerHeight}px`,

"animation": `lunbo ${speed*listLength}s linear infinite;`

});

style.insertRule(`@keyframes lunbo{

           100%{

               transform: translateX(-${contentWidth}px);

           }

       }`)

});


提问者:weixin_慕UI6578365 2020-12-21 11:44

个回答

  • 慕梦前来
    2022-01-12 18:43:41

    没有加载到样式表,文件有问题吧