Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint window scroll not firing

I have this HTML generated by my SharePoint page (clipped):

<body scroll="yes" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master" style="overflow: scroll" spellcheck="false">
    <form name="aspnetForm" method="post" action="/Lists/List/EditNewForm.aspx?ID=2&amp;Source=https%3A%2F%2Fsp2010-test%2Eatwss%2Ecom%2FLists%2FList%2FAllItems%2Easpx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" style="overflow: scroll">

// some html here

<div id="competenceTotalSum" style="position: absolute; left: 500px; top: 400px; width: 100px; height: 50px; background-color:gray" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){       
        $("form#aspnetForm").bind("scroll", function(e){
            alert("scroll");
            $("#competenceTotalSum").css("top", $(this).scrollTop() + 400);
        });
    });
</script>

// some html here

    </form>
</body>

Event scroll not firing. I changed scroll attribute of body, overflow properties of body and form, tried to bind scroll event to different objects (window, body, form). When change scroll event to click event - it fires. I didn't find any reasons of it except overflow property of scrolled element.

like image 434
Evgeny Levin Avatar asked Sep 10 '13 14:09

Evgeny Levin


1 Answers

It's kind of old Question but still this might be helpful for other, I wanted to implement scroll to top feature in one of my share point project.

After breaking my head around few hours. I got it working with below code.

actually $(window).scroll() wont fire in share point, I use there master id which is ('#s4-workspace') to get it work.

$(document).ready(function () {
    var offset = 220;
    var duration = 1000;

  jQuery('#s4-workspace').scroll(function() {

        if (jQuery(this).scrollTop() > offset) {
            jQuery('.arrowToTop').fadeIn(duration);
        } else {
            jQuery('.arrowToTop').fadeOut(duration);
        }
    });

    jQuery('.arrowToTop a').click(function(event) {
        event.preventDefault();
       jQuery('#s4-workspace').animate({scrollTop: 0}, duration);
        return false;
    }) });

I have used below CSS style

.arrowToTop {
   display: none;
   height: 100%;
   position: fixed;
   right: 20px;    
   z-index: 9999;
   bottom: 0;
   width: 70px;
   height:70px;
} 

.arrowToTop a{     
    width: 70px;
    height:70px; 
    display: block;
     background: url(../images/arrow.png) no-repeat left 0;
    }
like image 51
Anjum.... Avatar answered Nov 14 '22 09:11

Anjum....