2011-02-03 22 views
1

何らかの理由で、ユーザーが背景イメージと背景リピートを取得および設定できないようにする必要があります。 代わりに背景を使用します。jquery:イメージを取得して、背景から繰り返します。

バックグラウンドCSSから画像、繰り返し、位置を取得および設定する方法は?

ありがとうございます。

答えて

2

背景画像

行き方:

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

SETING:

$('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を繰り返します。 =>背景色、背景画像、背景反復などからではありません。ありがとうございます。 – 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]; 

を行うことができますそして今、私は助けることができますか?

関連する問題