【问题标题】:Error changing background image更改背景图片时出错
【发布时间】:2013-09-09 12:28:29
【问题描述】:

我正在尝试通过带有叠加层的 jQuery 更改不同页面的背景图像,但是,我做错了。有人可以指出我做错了什么吗?

$("html").css({"background-image": "url("+../images/pattern copy.png+")", "url("+../images/visuals/visual3-edit.jpg+")", "center" "center" "fixed no-repeat;"});

我希望我正确使用 StackOverflow,这是我第一次尝试这样做。

亲切的问候。

【问题讨论】:

  • 你可能想要$("html").css({ "background": "url(../images/pattern copy.png) center center fixed no-repeat" });

标签: jquery html image background


【解决方案1】:

改用这个:

$("html").css({ "background": "url('../images/visuals/visual3-edit.jpg') center center fixed no-repeat" });

或者如果您只是更改图像...

$("html").css({ backgroundImage: "url('../images/visuals/visual3-edit.jpg')" });

不确定您所说的其他页面是什么意思。能具体点吗?

另外,试试:

$("html").css({ "background-image": "url('../images/pattern%20copy.png'), url('../images/visuals/visual3-edit.jpg')", "background-position": "center", "background-repeat": "no-repeat", "background-attachment": "fixed"  });

另外,如果您的文件名中有空格,例如:pattern copy.png,那么实际的文件名路径将是:pattern%20copy.png

【讨论】:

  • 嗨,所罗门,感谢您的回复。基本上用户打开一个新页面,我想要一个不同的背景图像。我正在使用 jQuery 来更改属性 HTML 的 CSS。您提供的代码仍然给出语法错误。我试图弄清楚出了什么问题。图片的路径是正确的。
  • 好吧,../ 代码提升了一个级别,这是您想要的吗?如果 images 文件夹与 html 文件相关,则不会使用 ../
  • 是的,确实应该提高一个水平。
猜你喜欢
  • 1970-01-01
  • 2012-10-16
  • 2014-03-04
  • 2012-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-18
相关资源
最近更新 更多