jQuery悬停在固定的pozition中更改背景图像(jQuery hover change background image in fixed pozition)

编程入门 行业动态 更新时间:2024-10-28 01:27:03
jQuery悬停在固定的pozition中更改背景图像(jQuery hover change background image in fixed pozition)

您好我的项目我有一个背景图片

background: url('img/1.JPG') fixed;

当div (".boxy")将被悬停时,我试图使用jQuery更改此背景图像。 这是我在jQuery中设法做的

$(document).ready(function() { $(".boxy").hover( function() { $("body").css(??????); //what should i write here in order to change background image in img/2.JPG }, function() { $("body").css(??????); // what should i write here in order to chage background image in img/1.JPG } ); });

Hello on my project I have a background image

background: url('img/1.JPG') fixed;

I am trying to change this background image using jQuery when a div (".boxy") will be hoverd. Here is what i managed to do in jQuery

$(document).ready(function() { $(".boxy").hover( function() { $("body").css(??????); //what should i write here in order to change background image in img/2.JPG }, function() { $("body").css(??????); // what should i write here in order to chage background image in img/1.JPG } ); });

最满意答案

$(document).ready(function () { $(".boxy").hover(function () { $("body").css('backgroundImage', 'url(img/2.JPG)'); }, function () { $("body").css('backgroundImage', 'url(img/1.JPG)'); }); });

jsFiddle示例

$(document).ready(function () { $(".boxy").hover(function () { $("body").css('backgroundImage', 'url(img/2.JPG)'); }, function () { $("body").css('backgroundImage', 'url(img/1.JPG)'); }); });

jsFiddle example

更多推荐

本文发布于:2023-08-04 16:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   背景   jQuery   pozition   hover

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!