123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- const iframe = document.getElementById("headerIframe");
- let observer = null
- const backcolor = {
- index: { background: '#fff', color: '#1C1C28', logo: './image/logos.jpg' },
- project: { background: '#F6FEF9', color: '#3C86DF', logo: './image/logos.jpg' },
- mobile: { background: 'none', color: '#000', logo: './image/logos.jpg' },
- about: { background: 'none', color: '#000', logo: './image/logos.jpg' },
- dynamic: { background: 'none', color: '#000', logo: './image/logos.jpg' },
- customerNew: { background: '#fff', color: '#000', logo: './image/logos.jpg' },
- knowledgeField: { background: '#fff', color: '#000', logo: './image/logos.jpg' }
- }
- function removeListener() {
- if (observer) {
- observer.disconnect();
- }
- }
- function reinitIframe() {
- if (iframe) {
- const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- const iframeBody = iframeDocument.body
- observer = new MutationObserver(function(mutationsList, observer) {
- const bodyHeight = iframeBody.clientHeight;
- iframe.style.height = `${bodyHeight + 1}px`;
- });
- observer.observe(iframeBody, { attributes: true, childList: true, subtree: true });
- }
- }
- function handleScroll() {
- const scrollYnma = window.scrollY
- const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- let imgElement = iframeDocument.getElementById('logo');
- let headerItems = iframeDocument.querySelectorAll('.header-item')
- let headerView = iframeDocument.querySelector('.headerView')
- const urls = window.location.href
- const filed = urls.match(/\/([^\/]+)\.html$/) && urls.match(/\/([^\/]+)\.html$/)[1];
- if(scrollYnma > 1) {
- headerView.style.background = '#fff'
- imgElement.src = './image/logos.jpg'
- headerView.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)';
- headerItems.forEach(function(item) {
- item.style.color = '#000'; // 设置你想要的字体颜色
- });
- return
- }
- console.log(backcolor[filed], filed)
- headerView.style.background = (backcolor[filed] && backcolor[filed].background) || 'none'
- headerView.style.boxShadow = '0 0 0 rgba(0, 0, 0, 0)';
- imgElement.src = (backcolor[filed] && backcolor[filed].logo) || './image/logos.png'
- headerItems.forEach(function(item) {
- item.style.color = (backcolor[filed] && backcolor[filed].color) || '#fff'; // 设置你想要的字体颜色
- });
- }
- // 页面滚动事件
- document.addEventListener('scroll', handleScroll);
- iframe.onload = function() {
- reinitIframe();
- handleScroll()
- }
- window.addEventListener('beforeunload', function() {
- removeListener();
- document.removeEventListener('scroll', handleScroll);
- });
- // 设计稿尺寸
- function bodyScale() {
- var devicewidth = document.documentElement.clientWidth;
- var scale = devicewidth / 1920; // 设计稿的尺寸
- document.body.style.zoom = scale;
- }
- window.onload = window.onresize = function () {
- bodyScale();
- };
|