douju6542 2014-09-10 15:05
浏览 42

滚动浏览页面的相对百分比后,如何才能显示此弹出窗口?

I'm working on a Wordpress website which has an "article box" feature which suggests another article on the website after a user has scrolled to point X on the page.

The problem is that this is not a relative value, but an absolute one. Meaning that the box appears very early in longer articles, late in short articles, and is inconsistent across different screen resolutions.

The "article box" takes a few values set in the admin panel including "distance from the top", "which articles are displayed", the "article display view", "number of posts", and "disable time". I hope that provides context for the code excerpt below.

You can see a live example by scrolling down this page.

I've found the relevant JavaScript:

            /**
 * More stories box
 */
if(tds_more_articles_on_post_enable == "show") {
    //adding event to scroll
    jQuery(window).scroll(function(){

        var cookie_more_box = td_read_site_cookie('td-cookie-more-articles');
        //alert(cookie_more_box);

        //setting distance from the top
        if(!isNaN(parseInt(tds_more_articles_on_post_pages_distance_from_top)) && isFinite(tds_more_articles_on_post_pages_distance_from_top) && parseInt(tds_more_articles_on_post_pages_distance_from_top) > 0){
            var set_distance = parseInt(tds_more_articles_on_post_pages_distance_from_top);
        } else {
            var set_distance = 400;
        }

        if (jQuery(this).scrollTop() > set_distance && cookie_more_box != 'hide-more-articles-box') {
            jQuery('.td-more-articles-box').addClass('td-front-end-display-block');
        } else {
            jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
        }
    });

    //adding event to hide the box
    jQuery('.td-close-more-articles-box').click(function(){

        //hiding the box
        jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
        jQuery('.td-more-articles-box').hide();

How can I make it so the box appears once the user has reached a certain percentage on the page?

  • 写回答

2条回答 默认 最新

  • douyi6960 2014-09-11 04:02
    关注

    You can use the jQuery Waypoints library. You can either set it to fire some code when a particular element has scrolled into view, or you can set a percentage of the viewport for it to fire.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大