Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i follow this tutorial: http://tympanus.net/codrops/2012/05/07/experimental-page-layout-inspired-by-flipboard/

everything work fine until i want to change the cover, they using this code assign the cover photo if it's first page.

HTML

ASP.NET
<script id="pageTmpl" type="text/x-jquery-tmpl">           
   		<div class="${theClass}" style="${theStyle}"   runat="server" id="divContent">
   			<div class="front">
   				<div class="outer">
   					<div class="removed" style="${theContentStyleFront}">
   						<div class="inner">{{html theContentFront}}</div>
   					</div>
   				</div>
   			</div>
   			<div class="back">
   				<div class="outer">
   					<div class="removed" style="${theContentStyleBack}">
   						<div class="inner">{{html theContentBack}}</div>
   					</div>
   				</div>
   			</div>
   		</div>
   	</script>


Javascript

JavaScript
for( var i = 0; i <= this.pagesCount - 2; ++i ) {
                  var $page       = this.$pages.eq( i ),
                      pageData    = {
                          theClass                : 'page',
                          theContentFront         : $page.html(),
                          theContentBack          : ( i !== this.pagesCount ) ? this.$pages.eq( i + 1 ).html() : '',
                          theStyle                : 'z-index: ' + ( this.pagesCount - i ) + ';left: ' + ( this.windowProp.width / 2 ) + 'px;',
                          theContentStyleFront    : 'width:' + this.windowProp.width + 'px;',
                          theContentStyleBack     : 'width:' + this.windowProp.width + 'px;'
                      };
                  if( i === 0 ) {
                      pageData.theClass += ' cover';
                  }
                  else {
                      pageData.theContentStyleFront += 'left:-' + ( this.windowProp.width / 2 ) + 'px';
                      if( i === this.pagesCount - 2 ) {
                          pageData.theClass += ' cover-back';
                      }
                  }
                  $( '#pageTmpl' ).tmpl( pageData ).appendTo( this.$el );
              }


CSS

CSS
.page.cover .front .content {
        background: #ddd url(http://txm.com.au/wp-content/uploads/2013/10/TXM_Image_3.jpg) no-repeat center center;       
        background-size: cover;
            }


now i have 2 different aspx with 2 different cover pages, hence the code above is not working for me. i don't wan to create another js or css file just because i want the different cover photo. so i was thinking, is there any possible that i set the css value with html control. eg:

CSS
.page.cover .front .content {
               background: #ddd url(" + lbl1.Text + ") no-repeat center center;
               background-size: cover;
           }

   <asp:Label Text="http://txm.com.au/wp-content/uploads/2013/10/TXM_Image_3.jpg"  runat="server" ID="lbl1" />


i tried using the javascript to change the css, but seems like it can't find the class name, i got the error message: Cannot read property 'style' of undefined

JavaScript
var abc = document.getElementsByClassName("page cover")[0];
  abc.style.background = "#ddd url(http://txm.com.au/wp-content/uploads/2013/10/TXM_Image_3.jpg) no-repeat center center";


i also tried to change the css from code behine

C#
string strClass = divContent.Attributes["class"];
    if (strClass == "page cover")
    {
           // change css
    }

but the strClass return "${theClass}" instead of "page cover"
Posted
Updated 21-Jun-15 14:11pm
v3
Comments
Sergey Alexandrovich Kryukov 21-Jun-15 21:07pm    
Why doing all that? What is the idea behind "change CSS", how? If you want to change style, change style or add/remove class to an element.
—SA

1 solution

Please see my comment to the question. I cannot see any sense in the code you show. You cannot "change CSS", you can change styling of any elements, because this is a part of DOM which can be modified by JavaScript. If you want to change some styles dynamically using JavaScript, you can easily do it. You have the tag "jQuery" in your question tags. With jQuery, everything is already done for you:
http://api.jquery.com/category/css[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900