【发布时间】:2017-02-17 12:44:11
【问题描述】:
当我点击按钮时,我有以下 JS 在我的网站上更改背景
我想为这两个背景之间的过渡设置动画。 我该怎么做?
var ImageOne = true;
var UrlOne = "https://s24.postimg.org/itrww7ovp/capanaraeditada.png";
var UrlTwo = "https://s27.postimg.org/wylbf2t83/capanara.jpg";
function SwitchImage() {
if (ImageOne) {
ImageOne = false;
UpdateBackground(UrlTwo);
} else {
ImageOne = true;
UpdateBackground(UrlOne);
}
}
function UpdateBackground(Url) {
$("body").css("background", "url(" + Url + ") no-repeat center center scroll");
$("body").css("-webkit-background-size", "cover");
$("body").css("-moz-background-size", "cover");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="SwitchImage();">LUZ</button>
【问题讨论】:
标签: jquery html background jquery-animate transition