简体   繁体   English

如果我在最后一页上,则右导航箭头应该不可见

[英]if I am on the last page right navigation arrow should be invisible

I have news list in which new news is adding dynamically by appending 'li' to 'ul'.Its almost worked but the issue is all function are working on ONCLICK so when I go last news list page the right navigation is visible and when I click on that its get hide. 我有一个新闻列表,其中通过将'li'附加到'ul'来动态添加新新闻。它几乎起作用,但是问题是所有功能都在ONCLICK上起作用,所以当我转到上一个新闻列表页面时,可以看到正确的导航,当我单击它隐藏。

So I want if I am on the last page right navigation arrow should be invisible. 所以我想如果我在最后一页上,右导航箭头应该是不可见的。

This css to hide navigation arrows. 此CSS隐藏导航箭头。

.iconWrap.left,.hide-right{display: none;} .iconWrap.left-nav {display: block;}

This is navigation arrows structure: 这是导航箭头结构:

 <div class="iconWrap left"><a onclick="leftarrow()" id="leftNav"></a></div>
 <div class="iconWrap right"><a onclick="rightarrow()" id="rightNav"></a></div>

This is UL structure where li get append: 这是li获得附加的UL结构:

<ul id="news-list">----- Here all li adds dynamically----</ul>

this is the function to calculate records per page, total records: 这是计算每页记录总数的功能:

function NewsList(page, num_Per_Page){
    $("#news-list").html("");
    var start = parseInt(num_Per_Page) * parseInt(page);
    var end = start + parseInt(num_Per_Page);
    if(current_Page > 0){
        $(".iconWrap.left").addClass("left-nav");
    } else {
        $(".iconWrap.left").removeClass("left-nav");
    }
    for(var z=start; z<end; z++){
    if(news[z] == undefined) continue;
        $("#news-list").append('<li><a href="#">--li data here--</a></li>');
    }
}

below functions calling for navigation arrows: 下面的功能需要导航箭头:

function leftarrow(){
    if(current_Page > 0){
        current_Page--;                        
        populateNewsList(current_Page, num_Records_PerPage);
    }
}

function rightarrow() {
    if((current_Page + 1) != (Math.ceil(<?=count($this->news)?>/num_Records_PerPage))){
        current_Page++;
        populateNewsList(current_Page, num_Records_PerPage);                      
    } else {
        $(".iconWrap.right").addClass("hide-right");
    }
}

You could make it work even when function is executed onclick 即使在onclick上执行函数,也可以使其工作

Create a global variable that keeps count of total number of pages: 创建一个全局变量,以保留总页数:

var totalPages = Math.ceil(<?=count($this->news)?>/num_Records_PerPage))

You should make the logic of user interface different from the rest of the code. 您应该使用户界面的逻辑与其余代码不同。 Call the function after every time 'arrows' are clicked. 每次单击“箭头”后调用该函数。

function showArrows() {
    if (currentPage > 1)
        $(".iconWrap.left").addClass("left-nav");
    else
        $(".iconWrap.left").removeClass("left-nav");

    if (currentPage >= totalPages)
        $(".iconWrap.right").addClass("hide-right");
    else
        $(".iconWrap.right").removeClass("hide-right");
}

function NewsList(page, num_Per_Page){
    $("#news-list").html("");
    var start = parseInt(num_Per_Page) * parseInt(page);
    var end = start + parseInt(num_Per_Page);

    for(var z=start; z<end; z++){
        if(news[z] == undefined) continue;
        $("#news-list").append('<li><a href="#">--li data here--</a></li>');
    }
}


function leftarrow(){
    if(current_Page > 0){
        current_Page--;                        
        populateNewsList(current_Page, num_Records_PerPage);
    }
    showArrows();
}

function rightarrow() {
    if((current_Page + 1) != totalPages){
        current_Page++;
        populateNewsList(current_Page, num_Records_PerPage);                      
    } 
    showArrows();   // Call it every time arrows are clicked
}

You could also call showArrows() when the documents completes loading to set initial value 当文档完成加载以设置初始值时,您也可以调用showArrows()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用左右箭头键进行其他导航 - Using left and right arrow keys for additional navigation jQuery 选项卡导航 - 禁用第一个和最后一个箭头 - jQuery Tab Navigation - First and Last Arrow Disabled 将左右箭头导航添加到“ li id”元素 - Add left and right arrow navigation to “li id” element 键盘箭头导航不应考虑隐藏的特殊字符 - Keyboard arrow navigation should not consider hidden special characters FullCalendar按钮的放置月份名称应介于左右箭头之间 - FullCalendar Button Placement Month Name should be between left and right arrow 如果我在第一页上向右滑动并在最后一页上向左滑动,jQuery移动滑动将停止 - jquery mobile swipe stops if i swipe right on the first page and and left on the last page 为什么在我点击右侧的“箭头”后,我的页面不再显示我的“.wall”(.wall 是额外信息)[netflix 滑块] - Why doesn't my page show me my '.wall' anymore after i clicked on the right "arrow"(.wall is extra info) [netflix sliders] Jssor滑块-在页面加载时隐藏左导航箭头 - Jssor Slider - Hiding Left Navigation arrow on page load 在页面上卸载时,我想停止导航,当我在对话框上完成工作时,它应该导航 - on page unload,i want to stop navigation and when i complete my work on dialog then it should nevigate 如何在页面滚动功能中添加填充并在正确的时间使导航元素突出显示? - How can I add a padding to my page scroll function and keep the navigation elements highlight at the right time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM