身体背景图片和jquery
我了解jquery,但在尝试让某些东西正常工作时遇到了一些麻烦。
基本上我有一个 WordPress 网站,每个页面上的 body 标签都有不同的背景图像。我希望能够打开一个按钮,然后主体背景图像下降约 500 像素。
基本上我在页面顶部有一个隐藏的联系区域,当您单击按钮(a.contact)时,隐藏的联系区域(#contactArea)会通过从顶部下拉而显示,但是当 contactArea 掉落一些时我的背景图像将被隐藏,直到您再次单击该按钮。
我想要实现的是,当隐藏的 contactArea 被显示时,背景图像会下降(仍然完全可见),以便背景图像始终可见......我希望这是有道理的?!
我的CSS代码是:
body.page.page-id-240 {background:url(images/main-home-bg.jpg) 中心 600px 无重复;
我当前的 jquery 是:
$(window).load(function() {
$("#contactArea").css('height', '0px');
$("a.contact").toggle(
function () {
$("#contactArea").animate({height: "225px"}, {queue:false, duration: 500, easing: 'linear'} )
},
function () {
$("#contactArea").animate({height: "0px"}, {queue:false, duration: 500, easing: 'linear'})
}
);
});
如果有人可以提供帮助,我们将不胜感激! :-)
I am knew to jquery and I am having a bit of trouble with trying to get something working.
Basically I have a wordpress site, on each page is a different background image for the body tag. I want to be able to toggle on a button and then the body background image to drop about 500px.
Basically I have a hidden contact area on the top of my page, and when you click on the button(a.contact) the hidden contact area(#contactArea) is revealed by dropping down from the top, however when the contactArea drops some of my background image is hidden until you click on the button again.
What I am trying to achieve is that the background image drops (still completely visible) when the hidden contactArea is revealed, so that the background image is always visible.... I hope that makes sense?!
my css code is:
body.page.page-id-240 {background:url(images/main-home-bg.jpg) center
600px no-repeat;
My current jquery is:
$(window).load(function() {
$("#contactArea").css('height', '0px');
$("a.contact").toggle(
function () {
$("#contactArea").animate({height: "225px"}, {queue:false, duration: 500, easing: 'linear'} )
},
function () {
$("#contactArea").animate({height: "0px"}, {queue:false, duration: 500, easing: 'linear'})
}
);
});
If anyone could help it would be greatly appreciated! :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的的最简单方法是让公开联系人区域的代码向 body 标记添加一个额外的 CSS 类,例如
reposition-bg
。然后定义适当的CSS类来修改body的BG位置。这有道理吗?CSS:
并将 JS 更改为:
或者,如果您可以灵活地这样做并且不会妨碍您的 UI,则可以将
#contactArea
设置为position:absolute 因此它将定位在当前内容的顶部,而不是向下推。
Easiest way to achieve this is to have your code which exposes the contacts area add an additional CSS class to the body tag e.g.
reposition-bg
. Then define the appropriate CSS class to modify the body's BG position. Does that make sense?CSS:
and change your JS to:
Alternatively, if you have the flexibility to do so and it doesn't impede your UI, you could set the
#contactArea
to beposition: absolute
so it will be positioned over the top of your current content rather than pushing it down.