123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- <style>
- [v-cloak] {
- display: none;
- }
- ul,
- li {
- padding: 0;
- margin: 0;
- list-style: none;
- }
- html,
- body {
- width: 100%;
- height: 100%;
- margin: 0;
- overflow: hidden;
- }
- .scene {
- width: 100%;
- height: 100%;
- }
- #app {
- position: absolute;
- pointer-events: none;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: 100;
- }
- .progress {
- display: none;
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- height: 4px;
- }
- .progress div {
- height: 100%;
- width: 0;
- background-color: #f60;
- }
- #parts ul,
- #frames ul {
- display: flex;
- }
- #parts li {
- position: relative;
- color: #fff;
- padding: 5px;
- margin-right: 10px;
- cursor: pointer;
- }
- #parts li:hover,
- #parts li.active {
- color: #f60;
- }
- #parts li.active .progress {
- display: block;
- }
- #frames li {
- position: relative;
- margin-left: 5px;
- border: solid 1px transparent;
- cursor: pointer;
- }
- #frames li span {
- display: none;
- position: absolute;
- right: 0px;
- top: 0px;
- width: 16px;
- height: 16px;
- background-color: #fff;
- text-align: center;
- }
- #frames li.active {
- border: solid 1px #f60;
- }
- #frames li.active .progress {
- display: block;
- }
- .toolbar {
- pointer-events: all;
- position: absolute;
- left: 50%;
- top: 0;
- transform: translateX(-50%);
- }
- .bottom {
- pointer-events: all;
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- height: 200px;
- background-color: rgba(0, 0, 0, 0.5);
- }
- .bottom.disable {
- pointer-events: none;
- opacity: 0.5;
- }
- [xui_tags_view] .tag-body {
- max-width: 300px;
- position: absolute;
- left: 50%;
- bottom: 50px;
- transform: translateX(-50%) scale(0);
- transform-origin: bottom;
- transition: all 0.3s cubic-bezier(0.35, 0.32, 0.65, 0.63);
- }
- [xui_tags_view] .tag-body.show {
- transform: translateX(-50%) scale(1);
- }
- [xui_tags_view] .tag-body .tag-image {
- min-width: 230px;
- height: 76px;
- background: hsla(0, 0%, 100%, 0.8);
- box-shadow: 0 3px 6px 0 rgb(0 0 0 / 16%);
- border-radius: 2px;
- position: relative;
- margin-bottom: 30px;
- }
- [xui_tags_view] .tag-body .tag-image::before {
- content: '';
- display: inline-block;
- left: 50%;
- transform: translateX(-50%);
- width: 2px;
- height: 28px;
- bottom: -30px;
- background: linear-gradient(145deg, hsla(0, 0%, 100%, 0.8), hsla(0, 0%, 100%, 0));
- position: absolute;
- }
- [xui_tags_view] .tag-body .tag-image .tag-avatar {
- position: absolute;
- z-index: 99;
- width: 80px;
- height: 80px;
- background: #fff;
- box-shadow: 0 3px 6px 0 rgb(0 0 0 / 16%);
- border-radius: 2px;
- top: -14px;
- left: -12px;
- background-size: cover;
- pointer-events: none;
- }
- [xui_tags_view] .tag-body .tag-image .tag-title {
- padding: 10px 10px 10px 76px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- width: 240px;
- }
- [xui_tags_view] .tag-body .tag-image .tag-info {
- padding: 0 20px 0 76px;
- font-size: 12px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- </style>
- </head>
- <body>
- <div id="scene" class="scene"></div>
- <div id="app" v-cloak>
- <div class="toolbar">
- <button @click="play">{{ playing?'暂停':'播放' }}</button>
- </div>
- <div class="bottom" :class="{disable:disable}">
- <div id="parts">
- <ul>
- <li v-for="(part,index) in tours" :class="{active:index == partId}" @click="selectPart(index)">
- {{part.name || '片段_'+index}}
- <div class="progress"><div :style="{width:progressPart+'%'}"></div></div>
- </li>
- </ul>
- </div>
- <div id="frames" :partid="partId" :frameid="frameId">
- <div v-for="(part,index) in tours" v-show="partId == index" :length="part.list.length">
- <ul>
- <li v-for="(frame,index) in part.list" :class="{active:index == frameId}" @click="selectFrame(index)">
- <img style="width: 200px; height: 140px" :src="frame.enter.cover" />
- <div class="progress"><div :style="{width:progress+'%'}"></div></div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <script src="../dist/sdk/kankan-sdk-deps.js"></script>
- <script src="../dist/sdk/kankan-sdk.js"></script>
- <script src="./js/vue.min.js"></script>
- <script>
- var app = null
- new Vue({
- el: '#app',
- data() {
- return {
- tours: [],
- partId: 0,
- frameId: 0,
- progress: 0,
- progressPart: 0,
- disable: false,
- playing: false,
- }
- },
- mounted() {
- app = new KanKan({
- dom: '#scene',
- num: 't-JKNqv1o',
- })
- app.use('TagView', {
- render(data) {
- return `
- <span class="tag-icon animate" style="background-image:url(${data.icon})"></span>
- <div class="tag-body">
- <div class="tag-image">
- <div class="tag-avatar"></div>
- <div class="tag-title">${data.title}</div>
- <div class="tag-info">${data.content}</div>
- </div>
- </div>
- `
- },
- }).then(view => {
- view.on('rendered', () => {
- view.on('click', e => {
- var tag = e.data
- // 聚焦当前点击的热点
- view.focus(tag.sid)
- })
- view.on('focus', e => {
- document.querySelectorAll('[xui_tags_view] >div').forEach(el => {
- el.querySelector('.tag-body').classList.remove('show')
- })
- e.target.querySelector('.tag-body').classList.add('show')
- })
- })
- })
- app.use('TourPlayer').then(player => {
- player.on('play', ({ partId, frameId }) => (this.playing = true))
- player.on('pause', ({ partId, frameId }) => (this.playing = false))
- player.on('end', () => {
- this.playing = false
- // 兼容最后一个画面没有进度的问题
- this.progressPart = 100
- })
- var currPartId
- var currFrames
- var currProgress
- player.on('progress', ({ partId, frameId, progress }) => {
- // 画面进度
- this.partId = partId
- this.frameId = frameId
- this.progress = Number(progress * 100).toFixed(5)
- // 片段进度
- if (this.tours.length == 1) {
- this.progressPart = this.progress
- } else {
- if (currPartId != partId) {
- currPartId = partId
- currFrames = this.tours[partId].list.length
- this.progressPart = 0
- }
- this.progressPart += progress / currFrames
- }
- })
- })
- // 需要双向绑定时,重新设置数据
- app.TourManager.on('loaded', tours => {
- this.tours = tours
- app.TourManager.load(this.tours)
- })
- app.render()
- },
- methods: {
- async selectPart(partId) {
- if (this.disable) {
- return
- }
- this.partId = partId
- this.frameId = 0
- this.disable = true
- this.progress = 0
- this.progressPart = 0
- var player = await app.TourManager.player
- await player.selectPart(partId)
- this.disable = false
- },
- async selectFrame(frameId) {
- if (this.disable) {
- return
- }
- this.frameId = frameId
- this.disable = true
- this.progress = 0
- this.progressPart = 0
- var player = await app.TourManager.player
- await player.selectFrame(frameId)
- this.disable = false
- },
- async play() {
- var player = await app.TourManager.player
- this.progress = 0
- if (this.playing) {
- player.pause()
- } else {
- player.play()
- }
- },
- },
- })
- </script>
- </body>
- </html>
|