身体背景图片和jquery

发布于 2025-01-02 23:10:12 字数 972 浏览 0 评论 0原文

我了解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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无敌元气妹 2025-01-09 23:10:12

实现此目的的最简单方法是让公开联系人区域的代码向 body 标记添加一个额外的 CSS 类,例如 reposition-bg。然后定义适当的CSS类来修改body的BG位置。这有道理吗?

CSS:

body.reposition-bg {
    /*your new position for when contact area is exposed*/
    background-position-y: 200px 
}

并将 JS 更改为:

$(window).load(function() {
$("#contactArea").css('height', '0px');

$("a.contact").toggle( 
            function () { 
                $("body").addClass("reposition-bg");
                $("#contactArea").animate({height: "225px"}, {queue:false, duration: 500, easing: 'linear'} )
            }, 
            function () { 
                $("#contactArea").animate({height: "0px"}, {queue:false, duration: 500, easing: 'linear'}) 
            } 
    ); 


});

或者,如果您可以灵活地这样做并且不会妨碍您的 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:

body.reposition-bg {
    /*your new position for when contact area is exposed*/
    background-position-y: 200px 
}

and change your JS to:

$(window).load(function() {
$("#contactArea").css('height', '0px');

$("a.contact").toggle( 
            function () { 
                $("body").addClass("reposition-bg");
                $("#contactArea").animate({height: "225px"}, {queue:false, duration: 500, easing: 'linear'} )
            }, 
            function () { 
                $("#contactArea").animate({height: "0px"}, {queue:false, duration: 500, easing: 'linear'}) 
            } 
    ); 


});

Alternatively, if you have the flexibility to do so and it doesn't impede your UI, you could set the #contactArea to be position: absolute so it will be positioned over the top of your current content rather than pushing it down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文