You can read开发者_如何学Python your browser dimensions with jQuerys $document.height or with simple JS via height: window.innerHeight || document.body.clientHeight.
But how do I apply the value to a CSS class?
jQuery:
$('.targetClass').css('height',otherObject.height()+'px');
No need to overcomplicate this - you don't need to find a way to apply the height to a CSS class. Just give each of your <div>
s a class in the HTML:
<div class="viewport_height">This is some content.</div>
then use jQuery code similar to this:
var document_height = $(document).height();
$('.viewport_height').css('height', document_height + 'px');
to apply the measured height to all elements of that class.
For a more robust solution, attach a function to the window
's onresize
event to recalculate and apply the height whenever the viewport height changes.
You cannot rewrite/add new values to CSS properties/classes on the fly; you can write/rewrite/add values to elements.
You should post your situation, maybe there is a different way to do what you're trying to do.
$('#target').css('height',$(document.body).height()+'px')
(jQuery)
Find the rule object in a browser-specific way ( http://www.javascriptkit.com/domref/cssrule.shtml )
Then you can edit the style object of the rule object and actually change the CSS class definition
精彩评论