Montag, 5. Oktober 2015

CSS Attribut zur Laufzeit ändert


Die JQuery.css() Methode ermöglicht es recht einfach  CSS Attribute einer Klasse anzupassen oder zu Setzen.
Im folgenden Beispiel soll das Hintergrund Attribut der bootstrap „logo-bar“ dynamisch gesetzt werden, ohne die gesamte Klasse gegen eine neue auszutauschen, nur um ein Attribut zu ändern. 

CSS

.logo-bar{

           z-index:1030;

           width:100%;

           position:fixed;

           left:0px;

           top:0px;

           background:url(../../logo-hg.png) repeat-x top left;

    } 

Javaccript


<script type="text/javascript">

        $(document).ready(function () {

       if ( @model.JVId == 00001003) {

            $('.logo-bar').css({ "background": "url(../../logo-hg_Red.png) repeat-x top left" });

       }

       else

       {

             $('.logo-bar').css({ "background": "url(../../logo-hg.png) repeat-x top left" });

       }

        });

</script> 

Hier wird für im falle das die JVId 00001003 ist die das CSS Attribut der „logo-bar“ Klasse neu gesetzt. 


Bis zum nächsten mal

Keine Kommentare:

Kommentar veröffentlichen