|
@@ -21,14 +21,28 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
const slots = config.slots || []
|
|
const slots = config.slots || []
|
|
const D = new Date()
|
|
const D = new Date()
|
|
const dateTime = D.getTime()
|
|
const dateTime = D.getTime()
|
|
|
|
+ console.log(slots)
|
|
for (let i = 0; i < slots.length; i++) {
|
|
for (let i = 0; i < slots.length; i++) {
|
|
const v = slots[i]
|
|
const v = slots[i]
|
|
if (!v.creativesList || !v.creativesList.length) continue
|
|
if (!v.creativesList || !v.creativesList.length) continue
|
|
// 获取对应广告位置
|
|
// 获取对应广告位置
|
|
const ad_pos = document.querySelector('#sxtv-ad-' + v.slotId)
|
|
const ad_pos = document.querySelector('#sxtv-ad-' + v.slotId)
|
|
- if (!ad_pos) return console.error('广告位置不存在:#sxtv-ad-' + v.slotId)
|
|
|
|
|
|
+ if (!ad_pos) {
|
|
|
|
+ console.error('广告位置不存在:#sxtv-ad-' + v.slotId)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ const gg = document.createElement('div')
|
|
|
|
+ gg.innerHTML =
|
|
|
|
+ '<svg t="1734493782806" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9775" width="32" height="32"><path d="M560.88 658.8h69.68v15.44h-69.68z" p-id="9776" fill="#515151"></path><path d="M698.24 451.44V200h-46.56v251.44H372.32V200h-46.56v251.44H186V824h651.92V451.44zM505.12 600H396.16v90.72L352 700.08v-33.92l8-2.4V575.2h54.24l-1.84-8.8h45.84l1.68 8.8h44.88z m162.72 96.48H524.4v-60h143.44z m5.36-64.48H518.88v-23.36h61.12v-11.28h-22.16l-2.88 8.48H520V582.4h8.72l5.52-13.76H568l-2.32 6.64h14.32v-8h38.64v8h49.04v22h-49.04v11.36h54.56z" p-id="9777" fill="#515151"></path></svg>'
|
|
|
|
+ gg.style.position = 'absolute'
|
|
|
|
+ gg.style.top = 0
|
|
|
|
+ gg.style.right = 3
|
|
|
|
+ gg.style.zIndex = 999999
|
|
|
|
+
|
|
// 判定当前时间是否在creativesList的时间内
|
|
// 判定当前时间是否在creativesList的时间内
|
|
const ele = document.createElement('div')
|
|
const ele = document.createElement('div')
|
|
|
|
+ ele.style.position = 'relative'
|
|
|
|
+ ele.appendChild(gg)
|
|
for (let o = 0; o < v.creativesList.length; o++) {
|
|
for (let o = 0; o < v.creativesList.length; o++) {
|
|
const item = v.creativesList[o]
|
|
const item = v.creativesList[o]
|
|
const start = new Date(item.startDate + ' 00:00:00').getTime()
|
|
const start = new Date(item.startDate + ' 00:00:00').getTime()
|
|
@@ -39,7 +53,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
const showType = item.showType
|
|
const showType = item.showType
|
|
let e =
|
|
let e =
|
|
showType === 1
|
|
showType === 1
|
|
- ? generateCarouselAd(item, D, v.slotId)
|
|
|
|
|
|
+ ? generateCarouselAd(item, D, v.slotId, v.width || 0, v.height || 0)
|
|
: generateAlternateAd(item, D, v.slotId)
|
|
: generateAlternateAd(item, D, v.slotId)
|
|
if (e == -1) return
|
|
if (e == -1) return
|
|
ele.appendChild(e)
|
|
ele.appendChild(e)
|
|
@@ -50,13 +64,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
ad_pos.style.width = (v.width || 0) + 'px'
|
|
ad_pos.style.width = (v.width || 0) + 'px'
|
|
ad_pos.style.height = (v.height || 0) + 'px'
|
|
ad_pos.style.height = (v.height || 0) + 'px'
|
|
ad_pos.style.border = 'none'
|
|
ad_pos.style.border = 'none'
|
|
|
|
+ ad_pos.style.overflow = 'hidden'
|
|
|
|
|
|
ad_pos.appendChild(ele)
|
|
ad_pos.appendChild(ele)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 生成轮播广告
|
|
// 生成轮播广告
|
|
- const generateCarouselAd = function (generateCarousel = {}, D, slotId) {
|
|
|
|
|
|
+ const generateCarouselAd = function (generateCarousel = {}, D, slotId, width, height) {
|
|
const week = D.getDay() === 0 ? 7 : D.getDay()
|
|
const week = D.getDay() === 0 ? 7 : D.getDay()
|
|
const timeInterval = (generateCarousel.timeInterval || '')
|
|
const timeInterval = (generateCarousel.timeInterval || '')
|
|
.slice(week * 24, week * 24 + 25)
|
|
.slice(week * 24, week * 24 + 25)
|
|
@@ -64,7 +79,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
const H = D.getHours()
|
|
const H = D.getHours()
|
|
if (timeInterval[H] == 0) return -1
|
|
if (timeInterval[H] == 0) return -1
|
|
const T = (generateCarousel.showIntervalTime || 5) * 1000
|
|
const T = (generateCarousel.showIntervalTime || 5) * 1000
|
|
- return createCarousel(generateCarousel.stuffsList, T, slotId)
|
|
|
|
|
|
+ return createCarousel(generateCarousel.stuffsList, T, slotId, width, height)
|
|
}
|
|
}
|
|
|
|
|
|
// 生成交替广告
|
|
// 生成交替广告
|
|
@@ -223,7 +238,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
}
|
|
}
|
|
|
|
|
|
// 轮播
|
|
// 轮播
|
|
- function createCarousel(images, interval, slotId) {
|
|
|
|
|
|
+ function createCarousel(images, interval, slotId, width, height) {
|
|
|
|
+ console.log(images, interval, slotId, width, height)
|
|
// 创建轮播图容器
|
|
// 创建轮播图容器
|
|
const carouselContainer = document.createElement('div')
|
|
const carouselContainer = document.createElement('div')
|
|
carouselContainer.style = `
|
|
carouselContainer.style = `
|
|
@@ -237,8 +253,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
const imagesContainer = document.createElement('div')
|
|
const imagesContainer = document.createElement('div')
|
|
imagesContainer.style = `
|
|
imagesContainer.style = `
|
|
display: flex;
|
|
display: flex;
|
|
- width: ${images.length * 100}%;
|
|
|
|
- height: 100%;
|
|
|
|
|
|
+ width: ${images.length * width}px;
|
|
|
|
+ height: ${height}px;
|
|
transition: transform 0.5s ease;
|
|
transition: transform 0.5s ease;
|
|
`
|
|
`
|
|
|
|
|