2011-02-03 4 views
1

어떤 이유로, 사용자가 배경 이미지 및 배경 반복을 가져오고 설정하지 못하게해야합니다. 그러면 대신 배경을 사용합니다.jquery : get 및 set 이미지, 배경에서 반복 CSS

배경 CSS에서 이미지, 반복 및 위치를 가져오고 설정하는 방법은 무엇입니까?

감사합니다.

답변

2

배경 이미지

방법 :

$('selector').css('background-image'); 
$('selector').css('background-repeat'); 
$('selector').css('background-position'); 

최저치를 :

$('selector').css({ 
    backgroundImage: 'url(' + imageUrl + ')' 
    ,backgroundRepeat: 'repeat-x' 
    ,backgroundPosition: '10px 10px' 
});; 
+1

내 질문을 이해할 수 없다고 생각하지만 답변 해 주셔서 감사합니다. – graz

+0

자, 문제에 대해 자세히 알려 주시면 도와 드리겠습니다. 감사합니다 –

+0

백그라운드 색상, 이미지, 반복, 첨부 파일, 위치 => 배경에서 추출하는 방법 : rgb (255,255,0) url ('http://xxx.com/abc.jpg') 오른쪽 스크롤 0px. NOT from => 배경색, 배경 이미지, 배경 반복, 등 감사합니다. – graz

1

당신은 전체 스타일 속성을 얻을 JQuery와는 별도로 값을 얻을 수 있기 때문에, 그것을 구문 분석 할 수 있습니다.

// All style attribute value 
var strStyle = $('selector').attr('style'); 
// Find 'background' and store until the end. 
strStyle = strStyle.substring(strStyle.indexOf('background:')+11); 
// Strip the next rules 
var strBackground = strStyle.split(';')[0]; 

좀 더 간략하게

var strStyle = $('selector').attr('style'); 
var strBackground = strStyle.substring(strStyle.indexOf('background:')+11).split(';')[0]; 

을 그것을 할 수 있습니다 그리고 지금 내가 도울 수 있을까?