Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike><a href="https://stackoverflow.com/questions/14694930/callback-function-after-tooltip-popover-is-created-with-twitter-bootstrap/">Callback function after tooltip / popover is created with twitter bootstrap?</a> shows how to exend the javascript. Use this to add the placement based on the calculated position before show:</p> <pre><code>var tmp = $.fn.popover.Constructor.prototype.show; $.fn.popover.Constructor.prototype.show = function () { /* random placement add your calcuations based $(this).data('isotope-item-position'); on here: */ var items = Array('top','bottom','left','right'); this.options.placement = items[Math.floor(Math.random()*items.length)]; // from: https://stackoverflow.com/questions/5915096/get-random-item-from-array-with-jquery tmp.call(this); } </code></pre> <p>see: <a href="http://bootply.com/66412" rel="nofollow noreferrer">http://bootply.com/66412</a></p> <p><strong>Update</strong></p> <p>In your extend show function <code>this.$element</code> is a reference to the element which triggered the popover. You can use this to get its position (<a href="http://api.jquery.com/position/" rel="nofollow noreferrer">http://api.jquery.com/position/</a>).</p> <pre><code> var tmp = $.fn.popover.Constructor.prototype.show; $.fn.popover.Constructor.prototype.show = function () { var position = this.$element.position(); if(position.top&lt;50){this.options.placement = 'bottom'} else if(position.top&gt;150){this.options.placement = 'top'} else if(position.left&lt;200){this.options.placement = 'right'} else {this.options.placement = 'left'} tmp.call(this); } </code></pre> <p>see: <a href="http://bootply.com/66412" rel="nofollow noreferrer">http://bootply.com/66412</a> (also updated)</strike></p> <p><a href="https://stackoverflow.com/a/12656175/1596547">https://stackoverflow.com/a/12656175/1596547</a> will give a better solution by calling placement as a function:</p> <pre><code>var options = { placement: function (context, source) { var position = $(source).position(); if (position.top &lt; 100){ return "bottom"; } if (position.top &gt; 800){ return "top"; } if (position.left &gt; 484) { return "left"; } //if (position.left &lt; 485) { else { return "right"; } } , trigger: "click", title: 'popover', content: 'content of a popover' }; $('.element').popover(options); } </code></pre> <p><code>popover()</code> is not a 'live' function. When new elements are insert to the DOM you will have to call popover again. See <a href="http://www.infinite-scroll.com/" rel="nofollow noreferrer">http://www.infinite-scroll.com/</a> "all options" infinite scroll has an optional callback when new content is successfully loaded in. Use this to call popover() again. See: <a href="http://bootply.com/66524" rel="nofollow noreferrer">http://bootply.com/66524</a> (bootply don't load the second page).</p> <p>complete source:</p> <pre><code>function setpopover() { var options = { placement: function (context, source) { var position = $(source).position(); if (position.top &lt; 100){ return "bottom"; } if (position.top &gt; 800){ return "top"; } if (position.left &gt; 484) { return "left"; } //if (position.left &lt; 485) { else { return "right"; } } , trigger: "click", title: 'popover', content: 'content of a popover' }; $('.element').popover(options); } $(function(){ var $container = $('#container'); $container.isotope({ itemSelector : '.element', itemPositionDataEnabled: true }); $container.infinitescroll({ navSelector : '#page_nav', // selector for the paged navigation nextSelector : '#page_nav a', // selector for the NEXT link (to page 2) itemSelector : '.element', // selector for all items you'll retrieve loading: { finishedMsg: 'No more pages to load.', img: 'http://i.imgur.com/qkKy8.gif' } }, // call Isotope as a callback function( newElements ) { $container.isotope( 'appended', $( newElements ) ); setpopover(); } ); setpopover() }); </code></pre> <p><strong>NOTE</strong>: the position of your element is giving by jQuery's position (). This will give you the current position of an element relative to the offset parent. Contrast this with .offset(), which retrieves the current position relative to the document. see: <a href="http://api.jquery.com/position/" rel="nofollow noreferrer">http://api.jquery.com/position/</a>. isotope-item-position will give the same position. To set the position relative to the visible windows see: </p> <ul> <li><a href="https://stackoverflow.com/questions/5273453/using-jquery-to-keep-scrolling-object-within-visible-window">Using jQuery to keep scrolling object within visible window</a></li> <li><a href="https://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling">Check if element is visible after scrolling</a></li> </ul> <p>etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload