簡體   English   中英

我不明白以下javascript

[英]I do not understand the following javascript

我正在嘗試在移動設備上將側面導航調整到左側(即使在移動設備尺寸(小於768像素)時,它僅顯示在頂部導航下方。 我已經嘗試了所有我知道的東西,所以我決定問題必須出在我的JavaScript中,因為這不是我的強項之一。 我有點理解,因為我知道Java。 所以我想知道以下代碼的作用...

$(function() {
    function responsiveView() {
        var wSize = $(window).width();
        if (wSize <= 768) {
            $('#container').addClass('sidebar-close');
            $('#sidebar > ul').hide();
        }

        if (wSize > 768) {
            $('#container').removeClass('sidebar-close');
            $('#sidebar > ul').show();
        }
    $(window).on('load', responsiveView);
    $(window).on('resize', responsiveView);
});

就Java結構而言,將與之等效。 但是它正在使用jQuery。

注意 :很多函數都位於jquery庫中,因此下面不再顯示。 $ = jQuery

public Class $
{
    private void responsiveView()
    {
        int wSize = $.window().width();
        if(wSize <= 768) 
        {
            window.container.addClass('sidebar-close');//it retrieves a reference to the element and adds the className used by CSS
            $('#sidebar > ul').hide();//replaces each ul in the element with the id of sidebar. sorry didn't want to think about the java equivalent
        }

        if (wSize > 768) 
        {
            window.container.removeClass('sidebar-close');
            $('#sidebar > ul').show();//shows all ul within element with id of sidebar
        }
//this codes runs after function/methods are compiled
    $.window.on('load', responsiveView);//sets the function/method to run on window load event
    $.window.on('resize', responsiveView);//sets the function/method to run on window's resize event
    }
}

希望能有所幫助。 請記住,addclass將允許元素具有多個類。 因此,如果將您的CSS分配給該類,它將應用兩種樣式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM