jQuery Pagination by div height (not item)

后端 未结 4 1522
野趣味
野趣味 2021-01-03 08:21

I am interested in using jQuery to create automatic pagination for content based on the height of the content and the div, rather than by number of items. Most pagination ex

4条回答
  •  误落风尘
    2021-01-03 08:41

    I don't know of an existing solution. However with some JavaScript (using something like jQuery) you can compute the height of an element. $(element).height() for example. Using this method you could iterate through a loop of elements and add them to a div depending on the available room left (set as a constant I guess). So if I have 3 elements and my available height is 100 px and jQuery returns a height of 35 px for each element I'd show the first two and then add the last to a queue to be shown when the user clicks next.

    It'd be a little harder to split the text in mid-element but I suppose you could use string parsing to cut the text of the element in half, measure height, cut in half again, measure height etc. It wouldn't be pretty, but it'd probably work.

提交回复
热议问题