0

我是新手。这是代码。

    $(window).resize(function() {
        screenlarge();
    });
    $(window).resize(function() {
        screensmall();
    });
    function screenlarge()  {
      windowsize = $(window).width();
      if (windowsize < 1040) {
          $('#wrappernav').fadeOut("fast");
          $('#sidebar').fadeOut("fast");
          $('#wrappernavbg').fadeOut("fast");
          $('#navigationon').fadeIn("fast");
    }
    } 
    function screensmall()  {
      windowsize = $(window).width();
      if (windowsize >= 1040) {
          $('#wrappernav').fadeIn("fast");
          $('#sidebar').fadeIn("fast");
          $('#wrappernavbg').fadeIn("fast");
          $('#navigationon').fadeOut("fast");   
    }
    }
$(document).ready(function(){
    $('#naviclosed').bind('click', function () {
        $('#wrappernav').fadeIn("fast");
        $('#sidebar').fadeIn("fast");
        $('#wrappernavbg').fadeIn("fast");
        $('#navigationon').fadeOut("fast");
    });
        $("#arrow").bind('click', function(){
        $('#wrappernav').fadeOut("fast");
        $('#sidebar').fadeOut("fast");
        $('#wrappernavbg').fadeOut("fast");
        $('#navigationon').fadeIn("fast");
    });
});

我的问题是如何在按#arrow 时删除screenlarge() 和screensmall(),并在按#navigationon 时再次添加这些功能。

请帮忙!谢谢!

4

1 回答 1

0

First of all, merge screenlarge and screensmall into single function like sreenSize. Just for clarity.

To unbind the event, simply do

$(window).off('resize', screenSize);

If you have no other event handlers for 'resize' event, you can also do it like this:

$(window).off('resize');
于 2013-01-07T22:53:03.863 回答