How to add <li> view limit in a div content using javascript?

Hiptop

I am trying to add dynamically <li> view limit in a div content. I want to show only 3 <li> every time when scroll the div content.

I'm not sure but here is an example : http://bit.ly/1fikqQ8

Daniel Cheung

Old Answer

Like this? http://jsfiddle.net/bennwbpu/1/

$(function(){
    var liheight = $(".demo2 li").outerHeight();
    $(".demo2").outerHeight(liheight*3);
})

First we gather the outer height of one <li> and we apply thrice of it for the outer height of .demo2

If you want to snap to the top of nearest <li> every time a scroll event occurs, you can try: http://demos.flesler.com/jquery/scrollTo/


New Answer

Fiddle: http://jsfiddle.net/bennwbpu/7/

Too many lines... but will do. The thing I did to make this solution is a bunch of Googling and putting the pieces together.

Simplified version

$(function(){
    var lih = $(".demo2 li").outerHeight(),
        lst = 0,
        f=0;
    $(".demo2").outerHeight(lih*3).scroll(function(e){
        var $this = $(this)
            ,st = $this.scrollTop();
        function _scroll(n) {
            $this.css("overflow","hidden").stop().animate({scrollTop:lst+(n)*lih*3}, 500, "swing", function(){setTimeout(
                function(){                    
                    $this.css("overflow","auto");
                    setTimeout(function(){f=0},50);
                },500)
            })
        }
        if (!f) {
            f=1;
            if (st > lst)
                _scroll(1);
            else
                _scroll(-1);
       }
       lst = st;
    });
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add <li> view limit in a div content using javascript?

From Dev

How to add content in ckeditor using jQuery or JavaScript?

From Dev

How to view long content in draggable div using scrollbar?

From Dev

How to add content of file after text in div using jQuery?

From Dev

Add a class tag to "the changable content DIV of the chosen <li>"

From Dev

Using javascript to alter content of a <div>

From Dev

How to make the content div scrollable without using javascript

From Dev

How to strip HTML tags from div content using Javascript/jQuery?

From Dev

How can I change the content of a div using jquery and javascript?

From Dev

How to remove content within a parent div using javascript?

From Dev

how to retrieve content within a div using regex in javascript

From Dev

How to strip HTML tags from div content using Javascript/jQuery?

From Dev

How to remove a word/string from div content using javascript

From Dev

How to parse ul , li tags in android studio using jsoup without div and display it in recycler view?

From Dev

How to dynamically add the content in jsp page using javascript?

From Dev

How to dynamically add the content in jsp page using javascript?

From Dev

Javascript add li to ul using array

From Dev

How to delete an <li> element by using ul li:before and clicking on the content?

From Dev

Cannot add content to a div after using empty() on it

From Dev

Cannot add content to a div after using empty() on it

From Dev

How to add class to the third <li> element in javascript

From Java

how to add new <li> to <ul> onclick with javascript

From Dev

How to add a class to a div dynamically using JavaScript or Jquery?

From Dev

How to add data-animation="fadeinup" inside <div> using Javascript

From Dev

How to add "<li>" into "<ul>" using jquery?

From Dev

How to move caret to child li in a content editable div?

From Dev

How to move caret to child li in a content editable div?

From Dev

how to rotationally change the content of 'div' on mouseover on each 'li'

From Dev

How would I add a vertical aligned bar to a li with horizontal content?

Related Related

  1. 1

    How to add <li> view limit in a div content using javascript?

  2. 2

    How to add content in ckeditor using jQuery or JavaScript?

  3. 3

    How to view long content in draggable div using scrollbar?

  4. 4

    How to add content of file after text in div using jQuery?

  5. 5

    Add a class tag to "the changable content DIV of the chosen <li>"

  6. 6

    Using javascript to alter content of a <div>

  7. 7

    How to make the content div scrollable without using javascript

  8. 8

    How to strip HTML tags from div content using Javascript/jQuery?

  9. 9

    How can I change the content of a div using jquery and javascript?

  10. 10

    How to remove content within a parent div using javascript?

  11. 11

    how to retrieve content within a div using regex in javascript

  12. 12

    How to strip HTML tags from div content using Javascript/jQuery?

  13. 13

    How to remove a word/string from div content using javascript

  14. 14

    How to parse ul , li tags in android studio using jsoup without div and display it in recycler view?

  15. 15

    How to dynamically add the content in jsp page using javascript?

  16. 16

    How to dynamically add the content in jsp page using javascript?

  17. 17

    Javascript add li to ul using array

  18. 18

    How to delete an <li> element by using ul li:before and clicking on the content?

  19. 19

    Cannot add content to a div after using empty() on it

  20. 20

    Cannot add content to a div after using empty() on it

  21. 21

    How to add class to the third <li> element in javascript

  22. 22

    how to add new <li> to <ul> onclick with javascript

  23. 23

    How to add a class to a div dynamically using JavaScript or Jquery?

  24. 24

    How to add data-animation="fadeinup" inside <div> using Javascript

  25. 25

    How to add "<li>" into "<ul>" using jquery?

  26. 26

    How to move caret to child li in a content editable div?

  27. 27

    How to move caret to child li in a content editable div?

  28. 28

    how to rotationally change the content of 'div' on mouseover on each 'li'

  29. 29

    How would I add a vertical aligned bar to a li with horizontal content?

HotTag

Archive