?$(()=>{????????console.log("頁面加載完執(zhí)行");????????var?style?=?document.styleSheets[0];//獲取頁面加載樣式表????????????????//查找元素????????var?$marquee?=?$('.marquee');????????var?$content?=?$marquee.find('.content');//找到類名為content的元素????????var?$list?=?$content.find('.list');//找到類名為list的元素????????var?outerWidth=300,????????????outerHeight=327,????????????speed=4;????????var?$list?=?$content.find('.list');//????????var?listlength?=?$list.length;//list的個數(shù)????????var?contentWidth=outerWidth*listlength;//content的寬度???????????????//js設置?marquee的css樣式????????$marquee.css({????????????"width":`${outerWidth}px`,????????????"height":`${outerHeight}px`????????});?????????//js設置?content的css樣式?????????$content.css({????????????'width':`${contentWidth}px`,//設置寬度????????????'height':`${outerHeight}px`,????????????'animation':`run?${speed*listlength}s?linear?infinite`????????});?????????//js設置?list的css樣式????????$list.css({????????????'width':`${outerWidth}px`,????????????'height':`${outerHeight}px`????????});????????????????//?給樣式表注入一個規(guī)則????????style.insertRule(`@keyframes?run{????????????100%{????????????????transform:?translateX(-${contentWidth}px);????????????}????????}`)????????????})
2020-08-03
insertRule 規(guī)則無法注入的 我是這樣解決的:
var style = document.styleSheets[0];
style.insertRule(`@keyframes run {100%{transform:translateX(-${contentWidth}px);}} `)
把這個刪了,在marquee.css里面把動畫幀加上就得了:
@keyframes run {
????100%{
????????transform:translateX(-2400px);
????}
}
2020-01-30
整理了一下格式,嘗試了一下是沒有問題的呀。
請題主給些別的信息。