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

来源:4-2 js配合动画属性实现图片无限滚动效果

weixin_慕UI6578365

2020-12-21 11:44

$(()=>{

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);

           }

       }`)

});


写回答 关注

1回答

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

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

带你走入前端动画的世界

学习css3动画,并结合实际项目向大家展示应用技巧,使大家快速入门。

29783 学习 · 65 问题

查看课程

相似问题