if (localStorage.getItem('imageButtonClicked') === 'true') { document.getElementById('imageButtonContainer').style.display = 'none'; }
function loadImage() { // Load image var imageContainer = document.getElementById('image-container'); var img = document.createElement('img'); <!-- 替换为自己的Api,自己没有服务器也可用这个,不过有概率被墙 --> // 在URL末尾附加时间戳,避免浏览器缓存 img.src = 'https://60s-api.viki.moe/v2/60s?encoding=image-proxy' + new Date().getTime(); img.alt = '动态加载的图片'; img.style.maxWidth = '100%'; img.style.border = '2px solid #ddd'; img.style.marginTop = '0px'; // 图片的上边距 // Wrap the image with a fancybox link var fancyboxLink = document.createElement('a'); fancyboxLink.setAttribute('href', img.src); // Set href to image source for fancybox zoom fancyboxLink.setAttribute('data-fancybox', 'gallery'); // Add fancybox group (can be a gallery) fancyboxLink.appendChild(img); imageContainer.appendChild(fancyboxLink);
// Hide the image button and save the state in localStorage document.getElementById('imageButtonContainer').style.display = 'none'; localStorage.setItem('imageButtonClicked', 'true'); } </script> <!-- 这里的css和js别忘记换成公用cdn或者自己的 --> <link rel="stylesheet" href="/jquery.fancybox.min.css"> <script src="/jquery.min.js"></script> <script src="/jquery.fancybox.min.js"></script>