最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to get event when user scroll top of div? - Stack Overflow

programmeradmin6浏览0评论

can you please tell me how to get event when user scroll to top of the contend of div . I have div having some content scollable contend ,if user scroll to top I want to show a alert . /

 <div id="contend">Tendulkar (Listeni/ˌsətʃɪn tɛnˈduːlkər/; born 24 April 1973) is a former Indian cricketer widely acknowledged as the greatest batsman of the modern generation, popularly holds the title "God of Cricket" among his fans[2] He is also acknowledged as the greatest cricketer of all time.[6][7][8][9] He took up cricket at the age of eleven, made his Test debut against Pakistan at the age of sixteen, and went on to represent Mumbai domestically and India internationally for close to twenty-four years. He is the only player to have scored one hundred international centuries, the first batsman to score a Double Century in a One Day International, and the only player to plete more than 30,000 runs in international cricket.[10] In October 2013, he became the 16th player and first Indian to aggregate 50,000 runs in all recognised cricket (First-class, List A and Twenty20 bined).[11][12][13]
    In 2002, Wisden Cricketers' Almanack ranked him the second greatest Test batsman of all time, behind Don Bradman, and the second greatest ODI batsman of all time, behind Viv Richards.[14] Later in his career, Tendulkar was a part of the Indian team that won the 2011 World Cup, his first win in six World Cup appearances for India.[15] He had previously been named "Player of the Tournament" at the 2003 edition of the tournament, held in South Africa. In 2013, he was the only Indian cricketer included in an all-time Test World XI named to mark the 150th anniversary of Wisden Cricketers' Almanack.[16][17][18]
    Tendulkar received the Arjuna Award in 1994 for outstanding sporting achievement, the Rajiv Gandhi Khel Ratna award in 1997, India's highest sporting honour, and the Padma Shri and Padma Vibhushan awards in 1999 and 2008, respectively, India's fourth and second highest civilian awards. After a few hours of his final match on 16 November 2013, the Prime Minister's Office announced the decision to award Bharat Ratna, India's highest civilian award.[19][20] With the scientist C. N. R. Rao, he was conferred the award on 4 February 2014 by President Pranab Mukherjee in a special ceremony in the Durbar Hall of the Rashtrapati Bhavan. He is the youngest recipient to date and the first ever sportsperson to receive the award.[21][22] He also won the 2010 Sir Garfield Sobers Trophy for cricketer of the year at the ICC awards.[23] In 2012, Tendulkar was nominated to Rajya Sabha, the upper house of the Parliament of India.[24] He was also the first sportsperson (and the first without an aviation background) to be awarded the honorary rank of Group Captain by the Indian Air Force.[25] In 2012, he was named an Honorary Member of the Order of Australia.[26]
    In December 2012, Tendulkar announced his retirement from ODIs.[27] He retired from Twenty20 cricket in October 2013[28] and subsequently announced his retirement from all forms of cricket,[29] retiring on 16 November 2013 after playing his 200th and final Test match, against the West Indies in Mumbai's Wankhede Stadium.[30][31] Tendulkar played 664 international cricket matches in total, scoring 34,357 runs.[1</div>

can you please tell me how to get event when user scroll to top of the contend of div . I have div having some content scollable contend ,if user scroll to top I want to show a alert . http://jsfiddle/d9584/

 <div id="contend">Tendulkar (Listeni/ˌsətʃɪn tɛnˈduːlkər/; born 24 April 1973) is a former Indian cricketer widely acknowledged as the greatest batsman of the modern generation, popularly holds the title "God of Cricket" among his fans[2] He is also acknowledged as the greatest cricketer of all time.[6][7][8][9] He took up cricket at the age of eleven, made his Test debut against Pakistan at the age of sixteen, and went on to represent Mumbai domestically and India internationally for close to twenty-four years. He is the only player to have scored one hundred international centuries, the first batsman to score a Double Century in a One Day International, and the only player to plete more than 30,000 runs in international cricket.[10] In October 2013, he became the 16th player and first Indian to aggregate 50,000 runs in all recognised cricket (First-class, List A and Twenty20 bined).[11][12][13]
    In 2002, Wisden Cricketers' Almanack ranked him the second greatest Test batsman of all time, behind Don Bradman, and the second greatest ODI batsman of all time, behind Viv Richards.[14] Later in his career, Tendulkar was a part of the Indian team that won the 2011 World Cup, his first win in six World Cup appearances for India.[15] He had previously been named "Player of the Tournament" at the 2003 edition of the tournament, held in South Africa. In 2013, he was the only Indian cricketer included in an all-time Test World XI named to mark the 150th anniversary of Wisden Cricketers' Almanack.[16][17][18]
    Tendulkar received the Arjuna Award in 1994 for outstanding sporting achievement, the Rajiv Gandhi Khel Ratna award in 1997, India's highest sporting honour, and the Padma Shri and Padma Vibhushan awards in 1999 and 2008, respectively, India's fourth and second highest civilian awards. After a few hours of his final match on 16 November 2013, the Prime Minister's Office announced the decision to award Bharat Ratna, India's highest civilian award.[19][20] With the scientist C. N. R. Rao, he was conferred the award on 4 February 2014 by President Pranab Mukherjee in a special ceremony in the Durbar Hall of the Rashtrapati Bhavan. He is the youngest recipient to date and the first ever sportsperson to receive the award.[21][22] He also won the 2010 Sir Garfield Sobers Trophy for cricketer of the year at the ICC awards.[23] In 2012, Tendulkar was nominated to Rajya Sabha, the upper house of the Parliament of India.[24] He was also the first sportsperson (and the first without an aviation background) to be awarded the honorary rank of Group Captain by the Indian Air Force.[25] In 2012, he was named an Honorary Member of the Order of Australia.[26]
    In December 2012, Tendulkar announced his retirement from ODIs.[27] He retired from Twenty20 cricket in October 2013[28] and subsequently announced his retirement from all forms of cricket,[29] retiring on 16 November 2013 after playing his 200th and final Test match, against the West Indies in Mumbai's Wankhede Stadium.[30][31] Tendulkar played 664 international cricket matches in total, scoring 34,357 runs.[1</div>
Share Improve this question asked Mar 2, 2014 at 12:25 user2648752user2648752 2,2415 gold badges23 silver badges29 bronze badges 2
  • do have any idea of this concept ..:( – user2648752 Commented Mar 2, 2014 at 12:34
  • @crisbeto's answer should shed light on it more – anurupr Commented Mar 2, 2014 at 12:37
Add a ment  | 

2 Answers 2

Reset to default 6

Here's a fiddle: http://jsfiddle/d9584/1/ , don't forget that your div actually needs a height in order to be scroll-able.

Then you just bind the scroll event and get the position with $(this).scrollTop()

@crisbeto has got it ( jquery) $("#element").scrollTop() or natively document.getElementById("element").scrollTop


Throwing in an example of something I use for odd scroll elements here and there - has some extra ui nice to haves so thought worth posting up too

http://jsfiddle/5Jz8A/

In the Markup add a class of .content-scroller any elements you want to scroll.

$(".content-scoller").on("scroll",function() {    
    _contentDiv = $(this);    
    _contentDiv.addClass("scrolling"); 

    /* is it top ? */
    if(_contentDiv.scrollTop() ===0) { _contentDiv.removeClass("nottop"); }
    else { _contentDiv.addClass("nottop"); }

    /* have we stopped scrolling ? */
    clearTimeout($.data(this, 'this_timer'));   
       $.data(this, 'this_timer', setTimeout(function() {
        _contentDiv.removeClass("scrolling"); }, 100)); 
});

*^ check 'has scrolling stopped' neat shorthand from **@yckart's answer****

发布评论

评论列表(0)

  1. 暂无评论