use*_*286 1 javascript css jquery background-size
我在IE中遇到了背景大小的问题,所以我找到了一个允许它在IE中工作的JavaScript,但我只想要在屏幕宽度低于768像素时应用背景大小.
这是我目前的脚本:
$(window).resize(function() {
if($(window).width() > 768)
jQuery('#header').css( "background-size", "cover" );
});
Run Code Online (Sandbox Code Playgroud)
一旦你开始调整大小,这就有效,但是一旦你低于768,它就不会删除背景大小,初始状态也没有背景大小.有任何想法吗?谢谢!
你的答案几乎是正确的.您需要做的就是添加其他内容.
$(window).resize(function() {
if($(window).width() > 768) {
jQuery('#header').css( "background-size", "cover" );
} else {
jQuery('#header').css( "background-size", "whatever" );
}
});
Run Code Online (Sandbox Code Playgroud)
我很担心你在这个地方写作jQuery所以你能做的也是:
jQuery(function( $ ) { // DOM ready and secured jQuery's $ alias
// Use freely $ alias
var $header = $('#header'); // Cache your selectors
$(window).resize(function() {
$header.css({backgroundSize:$(this).width()>768?"cover":"whatever"});
});
// Other $ code here
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1237 次 |
| 最近记录: |