2012-07-10 76 views
0

我一直在研究一个需要跨浏览器兼容性的网站(包括较早的IE),并且我有一个使用渐变的边栏,但事实证明它的使用容易一百万倍设置背景图像,我有高度的图像重复正确的基础上取决于主容器的高度,但我想要做同样的宽度。重复基于div大小的图像

我知道如何根据其他人的尺寸来拉伸div,但我想知道如何获得一个条件语句,它会重复图像y直到div结束,因此它不会移动设置图像!

我实现使用这种基于重复的高度:

<script type="text/javascript"> 

var theHeight = $('#Container').height() - 260; 
$('#SecondaryContent').css('min-height', theHeight); 


</script> 

我试图用这个代码:

<script type="text/javascript"> 

var divWidth = $('#SecondaryContent').width() + 1; 


if (divWidth.width() > 200) { 
    alert('hello'); 
$('#SecondaryContent').css('background', 'url(../images/background_slice.png)', 'repeat-x 18% 0%'); 
} 


</script> 

但是似乎无法找到专区内任何东西。

+3

如何向我们展示一些代码,甚至更好地创造一个http:/ /jsfiddle.net/ – ManseUK 2012-07-10 08:41:22

+0

增加了高度JS – 2012-07-10 08:44:40

+0

创建jsfiddle请 – Feanor 2012-07-10 08:59:32

回答

0

只是想我会更新我设法得到这个工作使用这样的:

<script type="text/javascript"> 

$(document).ready(function() { 
    divExpander(); 
    divLineExpander(); 
    divWindowLineExpander(); 
}) 

function divExpander() { 
    var theHeight = $('#Container').height() - 260; 
$('#SecondaryContent').css('min-height', theHeight); 
} 

    function divLineExpander() { 
     var theWidth = $('#SecondaryContent').width() + 2; 
     $('#Navigation').css('min-width', theWidth); 
    } 

$(window).bind("resize", divWindowLineExpander); 
function divWindowLineExpander(e) { 
    var theLineWidth = $('#SecondaryContent').width() + 1; 
    $('#Navigation').css('min-width', theLineWidth); 
    } 

</script> 
0

这些CSS可以帮助

background-repeat: repeat; // repeats x and y 
background-repeat: repeat-x; // repeats x 
background-repeat: repeat-y; // repeats y 
+0

这完全没有帮助... – 2012-07-10 14:07:41