有的时候想弄个提交表单,但是在主题内的样式总是不合适,只好使用iframe来插入网页。
但是主题分为两种模式 手机 和电脑。在电脑上显示很合适,但是在手机上……不说了都懂得。
那么怎么才能在手机上美观的插入呢。
使用自适应吧。一切替你完成,附送加载状态 一枚。
看一送一,是不是很划算那!
var winWidth = 0; var winHeight = 0; var ratioWidth = 0; var ratioHeight = 0; function currentWindSize() //函数:获取当前窗口尺寸 { //获取窗口宽度 if (window.innerWidth) winWidth = window.innerWidth; else if ((document.body) && (document.body.clientWidth)) winWidth = document.body.clientWidth; //获取窗口高度 if (window.innerHeight) winHeight = window.innerHeight; else if ((document.body) && (document.body.clientHeight)) winHeight = document.body.clientHeight; //通过深入Document内部对body进行检测,获取窗口大小 if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) { winHeight = document.documentElement.clientHeight; winWidth = document.documentElement.clientWidth; } } //设置iframe高度 function setIframeHeight(winHeight) { $("#iframepage").height(winHeight - 100) } function resize() { currentWindSize(); setIframeHeight(winHeight); } //获取当前窗口大小 currentWindSize(); window.onresize = resize; setIframeHeight(winHeight);
var iframe = document.createElement("iframe"); iframe.src = "http://www.baidu.com"; iframe.style.overflowX = "hidden"; iframe.setAttribute("width", 1018); iframe.setAttribute("frameborder", "no"); iframe.setAttribute("border", "0"); iframe.setAttribute("marginwidth", "0"); iframe.setAttribute("marginheight", "0"); iframe.setAttribute("allowtransparency", "yes"); iframe.setAttribute("scrolling", "yes"); iframe.setAttribute("id", "iframepage"); iframe.setAttribute("name", "iframepage"); if (iframe.attachEvent) { iframe.attachEvent("onload", function () { document.getElementById("loading").style.display = "none"; }); } else { iframe.onload = function () { document.getElementById("loading").style.display = "none"; }; } document.getElementById("iframeDiv").appendChild(iframe);
438490 646458But wanna admit that this really is extremely helpful , Thanks for taking your time to write this. 978320
2018年8月14日 03:04这两段都是放到主题的js里面吗?
2016年8月2日 12:00-_-|| 其实不需要这么来的,宽度100%,高度用mobile判断,使用两种高度,我主题插入视频自适应就是这么处理的
2015年3月1日 15:46我不用加mobile判断
手机自动跳转至手机主题
2015年3月1日 15:50那个小人好可爱!
2015年1月23日 18:37自适应效果不错。
2015年1月9日 17:22海到天边云做岸,山登绝顶我为峰! !这话好熟悉。。。。。 仙路尽头谁为峰,一见无始道成空
2015年1月9日 13:05这是我最喜欢的一句话
2015年1月9日 18:38