| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- var cid
- function isWeChat() {
- let ua = window.navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == "micromessenger") {
- return true;// 是微信浏览器
- } else {
- return false;// 不是
- }
- }
- //返回按钮绑定 页面滚动过度处理
- function backCut() {
- $('.gameDetailPageContent').on('scroll', function (e) {
- let scrollTop = +e.target.scrollTop
- $('.backContent').css("background", `rgba(0, 0, 0, ${(Math.abs(scrollTop) / 20) > 0.4 ? 0.4 : Math.abs(scrollTop) / 20})`);
- })
- $('.backContent')[0].onclick = function () {
- window.location.href = '/game/index.html?&cid='+cid
- }
- }
- //微信下载提示
- function weixinHint() {
- let isWeixin = isWeChat();
- if (isWeixin) {
- $('.weixinHint').show();
- }
- if (!isWeixin) {
- $('.weixinHint').hide();
- }
- }
- //微信提示点击关闭提示
- function weixinHintBundClick() {
- $('.weixinHint')[0].onclick = function () {
- $('.weixinHint').hide();
- }
- }
- //图片预览
- let previewImg = ''
- //图片预览初始化
- function imgViewInit() {
- previewImg = new Viewer(document.getElementById('viewer'), {
- url: 'data-original',
- movable: false,
- toolbar: false,
- title: false,
- });
- }
- //查看更多绑定预览
- function moreView() {
- $('.moreCut')[0].onclick = function () {
- console.log(previewImg)
- if (previewImg) {
- //预览指定索引图片
- previewImg.view(0)
- }
- }
- }
- let imgTimer = ""
- //开启自动播放
- function openImgViewTimer() {
- let len = $('.navContent .nav_item').length
- if (!len) return;
- clearImgTimer();
- let index = $('.navContent .active').index() + 1
- imgTimer = setInterval(() => {
- if (index > len - 1) {
- index = 0
- }
- $('.navContent .nav_item').removeClass("active");
- $('.navContent .nav_item').eq(index).addClass('active')
- $('.swiperContent .swiperItem').removeClass('active')
- $('.swiperContent .swiperItem').eq(index).addClass('active')
- index++;
- }, 5000)
- }
- //清除计时器
- function clearImgTimer() {
- clearInterval(imgTimer);
- imgTimer = ''
- }
- //图片切换
- function navCutInit() {
- // 默认初始化
- if ($('.navContent .nav_item').length) {
- $('.navContent .nav_item').removeClass('active')
- $('.navContent .nav_item').eq(0).addClass('active')
- }
- if ($('.swiperContent .swiperItem').length) {
- $('.swiperContent .swiperItem').removeClass('active')
- $('.swiperContent .swiperItem').eq(0).addClass('active')
- }
- //右侧图片总数统计显示
- $('.moreCut span').text($('.navContent .nav_item').length)
- //切换增加
- $('.navContent .nav_item').click(function (e) {
- $('.navContent .nav_item').removeClass("active");
- $(this).addClass("active");
- //顶部展示同步
- $('.swiperContent .swiperItem').removeClass('active')
- $('.swiperContent .swiperItem').eq($(this).index()).addClass('active')
- openImgViewTimer();
- })
- console.log($('.navContent .active').index())
- }
- function init() {
- cid = getQueryString('cid')
- //微信浏览器提示开启
- weixinHint()
- //微信提示点击关闭
- weixinHintBundClick()
- //返回按钮
- backCut()
- // 图片预览初始化
- imgViewInit()
- //更多图片预览
- moreView()
- //图片切换
- navCutInit();
- //开启自动播放
- openImgViewTimer();
- }
- function getQueryString(name) {
- var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
- var r = window.location.search.substr(1).match(reg);
- if (r != null) {
- return unescape(r[2]);
- }
- return null;
- }
- init()
|