English 中文(简体)
jj 查询: 将图片隐藏在页面负载中
原标题:jQuery: hiding pictures on page load

I need to hide pictures when my internet page is loaded, and make them appear later on (they are triggers for other divs appearing/disappearing). The reason is that i don t want them to be clickable until my .animate() function actually makes them appear for real..
So anyways, I tried a simple...

$(document).ready(function(){
    $("#img1").hide();
    $("#img2").hide();
});

...与HTML...

<img id="img1" src="./images/img1.png" alt="image 1" />
<img id="img2" src="./images/img2.png" alt="image 2" />

...还有CSS

#img1
{
z-index: 4;
position: relative;
top: 0%;
left: 5%;
opacity: 0;
padding: 20px;
}
#img2
{
z-index: 4;
width: 350px;
height: 140px;
position: relative;
top: 0%;
left: 15%;
opacity: 0;
padding: 20px;
}

...但它没有起作用。

有什么想法吗?

最佳回答

首先,我会尝试在您的(文件)中设置一个 JS 警告 。 准备好功能以确保代码被正确击中( JQuery 引用, JS 语法可以 ) 。 此外, 通过在 Mozilla Firebug ( 或其他 JS 调试器) 中加个手表检查 JQuery 正在正确接收对象 ( “ img1 ”, “ img2 ” ) 。

您也可以尝试设置 Ing 的样式以显示: 在标记中没有显示, 如果它总是被隐藏在每次页面加载上的话 。

I.e.,

<img src="imgs/image.jpg" style="display:none"></img>

上述逻辑可以移到 CSS 。

当需要显示图像时, 请使用您的动画功能 。

问题回答

试试这个

$(document).ready(function(){
    $("#img1").css({display,  none });
    $("#img2").css({display,  none });
});

在所有图像中添加一个类, 并设置默认隐藏的可见属性, 稍后在动画函数或其它东西上, 删除该类 。 它将会工作 。

<style>
.hiddenclass
{
   display:none;
}
</style>

<img src="imgs/image1.jpg" class="hiddenclass"></img>

<img src="imgs/image2.jpg" class="hiddenclass"></img>

 ------

<img src="imgs/image3.jpg" class="hiddenclass"></img>

在动画脚本中,使用 removeClass 从所有图像中删除 hidden类

您也可以使用 .html () 函数

例如:http://jsfiddle.net/ipsjolly/jLNKL/





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签