I'd like to use https://github.com/lonekorean/mini-preview to create mouseover previews for parts of a website only.
I have no problems using anchors from the target website to have the script render a full website preview, scrolled to where an individual anchor is. That's not what I'm after however.
I'd like the script to show only the content of the anchors' parent <p> or <div>.
On the site, the link target anchors are coded like this:
<div class="paragraph">
<p>
<a id="anchor_1"></a>
Foo bar baz.
</p>
</div>
So, I'd like the little preview box to show Foo bar baz.
only.
I suspect the answer lies in this part of the script:
loadPreview: function() {
this.$el.find('.' + PREFIX + '-frame')
.attr('src', this.$el.attr('href'))
.on('load', function() {
// some sites don't set their background color
$(this).css('background-color', '#fff');
});
specifically, the .attr('src', this.$el.attr('href'))
part.
I'm not sure though.
Does anyone know how I can do this?
Or can you recommend some other script that I can use to do this and makes things look as nice as this one?
I'm not a web dev, so please go easy on me.
Thanks
UPDATE (based on Swati's answer and corresponding comments):
For example, if my website includes this:
<body>
<p>
<a href="#anchor_on_my_site">See internal</a>
</p>
<p>
<a href="external_website.html#external_anchor">See external</a>
</p>
<div class="paragraph">
<p>
<a id="anchor_on_my_site"></a>
Foo bar baz.
</p>
</div>
</body>
and the external website includes this:
<body>
<div class="paragraph">
<p>
<a id="external_anchor"></a>
Qux quux quuz.
</p>
</div>
</body>
I'd like See internal
to display Foo bar baz.
and See external
to display Qux quux quuz.
Inside
loadPreview
function you can useclosest('p').clone().children().remove().end().text()
to get text fromp
tag wherea
has been hover then using this put that text to show inside your frame div i.e :.find('.' + PREFIX + '-frame').text(data_to_show)
.Demo Code :
Update 1 :
You can differentiate between external & internal link using some class i.e : simply check if the
a
tag which is hover has a particular class or not depending on this change your code to preview divs.Updated Code :