加载外部页面时显示图像
display image while loading external page
我使用脚本在div内部加载外部页面(外部表示我网站上的页面(,所以我使用以下脚本加载页面,因为加载页面需要时间,所以我需要显示图像直到页面加载
脚本
function HideLoader() {
$('#loader').css('display', 'none');
}
function ShowLoader() {
$('#loader').css('display', '');
}
$(document).ready(function() {
$('.reveal').on('click', function(e) {
e.preventDefault();
ShowLoader();
var link = $(this).attr('href');
$('.page').load(link);
$('#leftmenu').css('width', '70px');
$("#leftmenu b,li ul").hide();
$('li').unbind('click');
$(this).show();
HideLoader();
});
});
.CSS
#loader {
display: unset;
width: 100px;
height: 100px;
margin: 100px;
}
.HTML
<div id="loader"> <img src="ajax-loader.gif" alt="loading" /> </div>
错误是点击链接前显示图像
我希望图像在单击链接时显示,并在加载页面时消失
解释一下...
CSS 更改为显示:无:
#loader {
display: none;
width: 100px;
height: 100px;
margin: 100px;
}
爪哇语更改此设置:
function ShowLoader() {
$('#loader').css('display', 'block');
}
而这个:
$('.reveal').on('click', function(e) {
var $that = $(this);
e.preventDefault();
ShowLoader();
var link = $(this).attr('href');
$('.page').load(link, function(){
HideLoader(); // this puts it in the load callback, so that this stuff
$that.show(); // happens when the load is complete
});
$('#leftmenu').css('width', '70px');
$("#leftmenu b,li ul").hide();
$('li').unbind('click');
});
您的div 始终可见。您需要更改 css 以使其默认不可见:
#loader {
display: none;
width: 100px;
height: 100px;
margin: 100px;
}
display: unset
仅使用标记的默认值,该值可见。
您还需要将showLoader
函数更改为:
function ShowLoader() {
$('#loader').css('display', 'block');
}
此外,在showLoader函数中,将显示值设置为"block"
相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何在生成下载文件时显示加载动画
- React重新渲染但未显示正确的组件
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 音频控件在mouseover上显示,在mouseout上淡出
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 显示5秒后隐藏潜水
- 画廊图像未显示
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 高亮显示时编辑文本大小和颜色
- 有时数据是't显示在浏览器中
- 当鼠标悬停在文本中的单词上时显示警报
- 角度图表;t显示在我的页面中
- 显示图工具提示显示x轴的最后日期值,而不是当前值