简体   繁体   中英

Resize function doesn't work

When the page loads I need #book to take 80% width of the window, and the same need to happen when page is resized. I make the code bellow, but it doesn't work. Why?

<script type="text/javascript">
    $(document).ready(function(){
        $('#book').turn();
        $("#book").width = 80 + "%";
    });
    $(document).resize(function(){
        $('#book').css('width', '80%');
    });
</script>

Thanks!

$("#book").width = 80 + "%"; isn't correct JS/jQuery.

You can change it to either

$('#book').css('width', '80%'); 

or

$('#book').width('80%');

Also, use $(window).resize() instead of $(document).resize()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM