我不确定这是否可行,但我希望如果您在选择菜单中选择一个选项,背景将在页面上更改
也可以通过动画淡出淡出淡出来完成吗?
HTML:
<br><br><br>
<select class="form-control select">
<option> Show London Background Picture</option>
<option> Show Paris Background Picture</option>
<option> Show Italy Background Picture</option>
</select>
<br>
<div class="jumbotron">
IF LONDON SELECTED THEN BACKGROUND: <br>http://www.manners.nl/wp-content/uploads/2014/08/Manners-stijlvolste-steden-londen-6.jpg<br><br>
IF PARIS SELECTED THEN BACKGROUND: <br>
http://travelnoire.com/wp-content/uploads/2013/12/eiffel-tower-paris-2.jpg<br><br>
IF ITALY SELECTED THEN BACKGROUND: <br>
https://upload.wikimedia.org/wikipedia/commons/5/53/Colosseum_in_Rome,_Italy_-_April_2007.jpg</div>
</div>
CSS:
body {
background-image: url("http://www.manners.nl/wp-content/uploads/2014/08/Manners-stijlvolste-steden-londen-6.jpg");
background-attachment: fixed;
background-position: 50% 50%;
background-size: cover;
}
答案 0 :(得分:0)
您可以将一个函数应用于select元素的onchange事件,该事件会更改您网站的背景图片:
$('#ID_OF_YOUR_SELECT').change(function() {
$('body').css('background-image', 'url("' + this.value + '")');
});
以下是基于您的示例更新的codepen: http://codepen.io/anon/pen/yNvapW
答案 1 :(得分:0)
答案 2 :(得分:0)
这会更改proceed = function() {...};
ajax_completed = false;
$.ajax(...,
success: function(data) {
ajax_completed = true;
...
}
);
$("#btn").on('click', function(ev){ if(ajax_completed) {...} });
的类,并在body
值更改时淡出背景。
select
&#13;
//set background based on default select value
$(document).ready(
function() { changeBackground.call($('.form-control')); }
);
//change background when select value is changed
$('.form-control').change(function() {
changeBackground.call($(this));
});
function changeBackground() {
var $body = $('body');
var values = "";
this.children('option').each(function() {
values += $(this)[0].value + " ";
});
var selectedValue = this[0].value;
$body.removeClass(values.replace(selectedValue, ""));
$body.addClass(selectedValue);
};
&#13;
body {
background-attachment: fixed;
background-position: 50% 50%;
background-size: cover;
-webkit-transition: background-image 500ms ease;
transition: background-image 500ms ease;
}
body.london {
background-image: url("http://www.manners.nl/wp-content/uploads/2014/08/Manners-stijlvolste-steden-londen-6.jpg");
}
body.paris {
background-image: url("https://images.indiegogo.com/file_attachments/620900/files/20140602122905-paris.jpg?1401737345");
}
body.italy {
background-image: url("http://www.liberty-int.com/Public/Italy-Signature-Slide5-Venice.jpg");
}
&#13;